Skip to main content

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [function]

Questions on function usage in the context of Unix & Linux (mostly but not exclusively shell scripts). Questions on programming in Python, Perl, Ruby, etc. should be asked on Stack Overflow.

Filter by
Sorted by
Tagged with
3 votes
2 answers
138 views

Localising variables in /bin/sh functions

POSIX defines shell functions as: fname ( ) compound-command [io-redirect ...] The compound-command is further defined as either: ( compound-list ) { compound-list ; } In particular POSIX notes for ...
Chris Davies's user avatar
0 votes
1 answer
59 views

How to keep a local function private in a zsh `autoload` module?

I want to define a helper function in a zsh autoload-ed module. The problem is, if I just define in my my_autoloaded_fn file such as function helper { # ... } helper a helper b the name helper ...
Petr's user avatar
  • 1,776
2 votes
4 answers
195 views

Is there a Bash variable containing the name of the previously executed function?

I want to line up a couple of Bash functions based on the success or failure of the execution of the preceding function. If something fails, I want to print an error message: function_x has failed. ...
vrms's user avatar
  • 287
0 votes
0 answers
28 views

Why is set -e also ignored for functions called via command substitution [duplicate]

I've seen questions about this topic, but they talk about constructs like if or ||. I don't understand why the same behavior seem to happen for substitution ($())? $ my_function() { echo "the ...
Jakub Bochenski's user avatar
4 votes
1 answer
272 views

Run in background avoiding any job control message from the shell [duplicate]

Lets define a shell function (here the shell is Bash) and test it $ s () { xterm -e sleep 5 & } $ s [1] 307926 $ [1]+ Done xterm -e sleep 5 $ With my specific meaning of ...
gboffi's user avatar
  • 1,386
7 votes
1 answer
594 views

bash - how to remove a local variable (inside a function)

I've read what's listed in Bibliography regarding unset, declare, local and "Shell Functions". My version of Bash is GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu) var='outer' ...
the_eraser's user avatar
2 votes
1 answer
211 views

Why does a 'pipe-to-awk' behave differently inside a function?

I'm using alsa to fiddle around with the volume on a Bluetooth speaker I have connected. It's a 1-speaker setup; just something to provide some background. I can 'get' the volume setting fm the CLI as ...
Seamus's user avatar
  • 3,792
3 votes
1 answer
609 views

Strange variable scope behavior when calling function recursivly

EDIT: sorry. this is my first question here. Here is a minimal working example #!/bin/bash # count=0 function something() { if test -f "$1"; then # is a file ((count++)) ...
Shlomo V's user avatar
-1 votes
1 answer
183 views

Override tr in ~/.bashrc

I'm trying to create a function to translate words via a custom script: function mean() { ~/scripts/translate.sh $1 } I would prefer the function to be named tr, as it is much shorter and faster ...
algonell's user avatar
3 votes
1 answer
335 views

How to overload / customize bash (or any other shell) commands handler?

When in bash some non existing command is run, corresponding error message appears: $ non-existent-command non-existent-command: command not found Is it possible to customize this behavior? I would ...
Anton Samokat's user avatar
3 votes
2 answers
392 views

how to alias the `history` function in fish shell

I'm trying to set the fish history pager to be bat -l fish for syntax highlighting. (i.e. set the PAGER environment variable bat -l fish just for the history command). I tried: # 1: alias history &...
matan h's user avatar
  • 149
0 votes
2 answers
97 views

Bash scripting: When to use variable, when function?

basic, innocent question: In bash scripting, why ever using a function, if one can set a variable containing command substitution with the essence of the function - a certain command or set of ...
futurewave's user avatar
2 votes
0 answers
48 views

Can't unalias then redefine as a function in the same conditional [duplicate]

Here is a simplified implementation of an issue in my bash/zsh aliases file: alias foobar='echo bar' # this is out of my control if true; then unalias foobar echo we got inside the conditional ...
Adam Katz's user avatar
  • 4,192
1 vote
1 answer
2k views

How to get function keys working on a Yunzii keyboard?

I have a Yunzii B705 keyboard. It has a row of multimedia keys that double as the function keys. Neither the multimedia nor function keys can work. I don't care about using the multimedia functions, ...
Village's user avatar
  • 4,207
0 votes
4 answers
830 views

return value of a function

Can somebody explain me, why the return value of a bash function is always echoed in the function and then consumed by my_var=$(my_func arg1 arg2 ..), when i look through code examples. my_func () {...
Schmaehgrunza's user avatar

15 30 50 per page
1
2 3 4 5
39
Morty Proxy This is a proxified and sanitized view of the page, visit original site.