Questions tagged [functions]

79 questions
34
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
  • 6,175
26
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
  • 12,304
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нιη
  • 36,350
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
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
  • 177
11
votes
2 answers

Should I put functions in .bashrc, .bash_aliases or .profile

I have read this thread about where to put aliases. Now, let's suppose that my custom command is quite elaborate (takes arguments in input, is composed of several commands run one after the other, I want to preserve it multi-line for clarity's sake,…
Tms91
  • 595
10
votes
2 answers

Show Shell Function in Ubuntu Terminal

Over the years I've moved away from using aliases to defining functions in a .functions file that I source at the time of launching the shell. This works fine, but one feature of alias that I miss is being able to see what a particular function…
Tex
  • 155
9
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
  • 679
  • 1
  • 9
  • 24
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…
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.
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…
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
  • 426
  • 4
  • 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
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,504
1
2 3 4 5 6