Skip to main content

All Questions

Tagged with
4 votes
1 answer
162 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,336
7 votes
1 answer
559 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
186 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,727
3 votes
1 answer
525 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
156 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
248 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
0 votes
2 answers
76 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
47 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,132
0 votes
4 answers
291 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
1 vote
2 answers
119 views

Start interactive function definition from shell-script

Using zsh or bash, I want to run a script that may prompt the user for multiple commands and store them as a function, however I'm finding that eval "function $FNCNAME() {" or echo "...
Joakim Hagen's user avatar
1 vote
3 answers
356 views

Run nested local bash functions via ssh

I have a script like this that declares many functions which use another functions, etc.: #!/bin/bash function a { ... } function b { ... a ... } ... And another script that uses ...
k1r1t0's user avatar
  • 133
0 votes
1 answer
322 views

how to write function with nested commands [duplicate]

I'm trying to write a find and cd function like so: findcd () { cd "$(dirname "$(find '$1' -type '$2' -name '$3')")" } to be called like so: find . f [FILE_NAME] But it's ...
Mathew's user avatar
  • 243
1 vote
1 answer
245 views

Run `git commit -m` with single quotes in zsh

I sometimes use characters such as ! and $ in commit messages, they need to be manually escaped, but not if you use single quotes like this git commit -m 'My $message here!'. I tried to write a ...
Justin Breen's user avatar
0 votes
1 answer
658 views

Running a function as process with a set process name or id

I have a bash script set up to monitor a number of UDP streams and convert it into actionable data. My problem is that I need to set the script to periodically check to see if the stream capture is ...
Dan D's user avatar
  • 3
0 votes
2 answers
194 views

How we can recursively expand inline functions and aliases inside function?

Nesting problem with duck typing: function f1 { echo $1; } #with argument function f2 { N=$((0+1)); f$N "fff"; } #with dynamic name Desired result: function f2 { { echo $1; } "fff"...
mr.tee's user avatar
  • 119

15 30 50 per page
1
2 3 4 5
25