Questions tagged [functions]

73 questions
33
votes
3 answers

How can I find where certain bash function is defined?

There are many functions that can be used in Bash shell. Their definitions can be listed by set, but how to find in which files certain user defined functions are defined?
jarno
  • 5,317
  • 5
  • 49
  • 77
24
votes
3 answers

Where can I put a user-defined shell function?

I am planning to create a function that would simplify things for me. The function would be something like function lazymode() { echo "Hello World!"; } so that when I use the command lazymode in the shell , it will output the Hello World!. What…
23
votes
2 answers

How can I protect parentheses passed to a cd command?

I asked here how to make cd protect spaces. Tab completion is great, but sometimes you paste the path from the clipboard so this is useful. The solution breaks with parentheses however. No matter how you try to escape and protect the input it always…
Strapakowsky
  • 11,664
  • 15
  • 36
  • 40
13
votes
7 answers

How to make the argument as optional in bash?

In below function with 9 arguments: SUM() { echo "The sum is $(($1+$2+$3+$4+$5+$6+$7+$8+$9))" } I want to make the second arguments to the next(3..9) become a optional arguments. When I call the function with 2 arguments I get error: SUM 3…
αғsнιη
  • 35,092
  • 41
  • 129
  • 192
12
votes
1 answer

What does _expand do?

I was working with the shell, and by mistake I autocompleted with tab after writing _e, which resulted in _expand. What does this command do? I couldn't find an explanation online, the only references I could find here on Ask Ubuntu were: Cannot…
0x5C91
  • 221
  • 1
  • 7
12
votes
3 answers

Mistake in shell function to count even numbers

For an assignment I have to write a function that prints the number of even numbers when provided with a sequence of numbers. I used the piece of code I used for a previous assignment (to print 1 when a number was even and 0 when the number was…
Jedidja
  • 167
  • 2
  • 9
8
votes
2 answers

How to pass arguments to functions while executing a python script from terminal?

I have a python file named solution.py and I can successfully execute it through the terminal using the following commands: chmod +x solution.py python3 solution.py This works just fine if I have simple print phrases and so on. What should I do if…
user253956
  • 267
  • 2
  • 3
  • 7
7
votes
0 answers

Is there a Libreoffice Calc function to translate languages?

Is there a Libreoffice Calc function to translate languages? I would like to write words into my spreadsheet and then automatically copy and translate them into german into a new cell.
Charlie Plett
  • 71
  • 1
  • 3
7
votes
2 answers

How can I use an alias in a function?

In my dotfiles I have some functions that rely on aliases or functions to exist for them to work. For some reason, I can get them to reference other functions I have created, but not aliases for commands. How do I fix this? Example: function…
oligofren
  • 630
  • 9
  • 20
6
votes
2 answers

Dollar Value To Word In LibreOffice Calc

I am wondering if there a way to convert a dollar value into words within LibreOffice Calc version 6.0.3.2 $1932.19 Would Become One Thousand Nine Hundred Thirty Two Dollars And Nineteen Cents I've found this function. It was lasted updated in…
Ron Piggott
  • 678
  • 4
  • 11
  • 26
5
votes
2 answers

How do you print/recall the definition of a function in bash

I can define and print the contents of variable called my_var like this: my_var="hello" echo $my_var but if I define: my_funct {echo "hello";} how can I recall my function's definition later on?
Robert Vila
  • 406
  • 2
  • 10
4
votes
1 answer

bash function cannot change the value of a local variable when called by $()

The following code works differently depending on which way Parse_Short_Switches() is called. After calling the function 'Parse_Short_Switches' by using result=$(Parse_Short_Switches), the value of $error_flag is NOT set to -1 as I would…
BASH
  • 61
  • 2
  • 3
4
votes
1 answer

SSH session doesn't export functions

I have a bunch of functions stored in ~/.bash_functions, which is sourced by ~/.bashrc on shell startup. The file exports all the functions like so: # Find functions in this script based on a grep search, and export them. grep ^'[[:alnum:]]'…
wjandrea
  • 14,109
  • 4
  • 48
  • 98
4
votes
2 answers

How to get original system command after overwriting it with a function?

I'm at a Hackathon right now so if someone would answer this soon, you'd be doing me a huge favor. I've written a function called ls() in my .bashrc that looks like this: ls() { if(some condition); do something else ls; #(CALL TO…
Programming Noob
  • 1,149
  • 7
  • 15
  • 23
3
votes
2 answers

Batch Starting Servers

How I can create a batch alias for bash? I need to do this: cd /somefolder bundle exec unicorn -p 3000 rackup faye.ru -s thin -E production bundle and rackup - this is 2 servers for example I want bind alias z=*all_of_this*
1
2 3 4 5