The function tag has no wiki summary.
9
votes
4answers
270 views
difference between function foo() {} and foo() {}
I can define bash functions using or omitting the function keyword. Is there any difference?
#!/bin/bash
function foo() {
echo "foo"
}
bar() {
echo "bar"
}
foo
bar
Both calls to functions ...
1
vote
1answer
37 views
Gawk: Passing arrays to functions
Stuck with GNU awk 3.1.6 and think I've worked around its array bugs but still have what looks like a scope problem in a 600-line awk program. Need to verify understanding of array scope in awk to ...
3
votes
1answer
196 views
for loop in bash function
I recently wrote the following bash function:
makeaudiobook () {
count=1
almbumartist=$2
for f in $1; do
preprocess $f > $f-preprocessed
text2wave $f-preprocessed -o $f.wav
...
1
vote
2answers
65 views
Best way to call command within a shell function having the same name [duplicate]
I like to encapsulate commands within shell-functions using the same name. But to avoid the shell-function calling itself recursively, I specify the complete path of the command as the following ...
4
votes
1answer
68 views
How can I create a function in zsh that calls an existing command with the same name?
How can I write a function in zsh that invokes an existing command with the same name as the function itself? For example, I've tried this to illustrate my question:
function ls
{
ls -l $1 $2 $3
...
2
votes
1answer
45 views
How to get functions propagated to subshell?
Solaris / sh
I have a few functions defined in a file which gets loaded via
. ./some_file.sh
When I start a subshell with
sh
All my function definitions are lost but when I do
env
I do ...
4
votes
2answers
91 views
How to define a Bash function that can be used by different scripts
I have defined a bash function in my ~/.bashrc file. This allows me to use it in shell terminals. However, it does not seem to exist when I call it from within a script.
How can I define a bash ...
2
votes
3answers
131 views
What are commands to find shell keywords, built in functions and user defined functions?
I was discussing with my friend on how the commands are parsed in the shell, and he told me that bash searches the command in following order
List of aliases
List of shell keywords
List of ...
8
votes
3answers
160 views
Running an executable in PATH with the same name as an existing function
Sometimes I define a function that shadows an executable and tweaks its arguments or output. So the function has the same name as the executable, and I need a way how to run the executable from the ...
4
votes
2answers
225 views
Bash function not working in Zsh
I have been slowly migrating from Bash to Zsh and have got to the point where everything I have moved across is working well, with one exception.
I have a couple of functions in my .bashrc that I use ...
3
votes
2answers
103 views
Display the function body in bash
I have setup several functions in my .bashrc file. I would like to just display the actual code of the function and not execute it, to quickly refer to something.
Is there any way, we could see the ...
4
votes
1answer
127 views
what is the zsh equivalent of bash's export -f
So I started using zsh. I like it all right. It seems very cool and slick, and the fact that the current working directory and actual command line are on different lines is nice, but at the same time, ...
1
vote
1answer
57 views
How to reference a script-local dictionary in a Vim mapping?
Somehow I'm not able to execute the following mapping:
function! s:MySurroundingFunctionIWantToKeep()
let s:Foobar={'foo': 'bar'}
map \42 :echo <sid>Foobar.foo<cr>
endfunction
call ...
2
votes
3answers
191 views
How to reverse-match a string in the Vim programming language?
I want to find the last index of any character in the [abc] set in the abcabc string but the search should start from the end of the string:
" Returns the 0th index but I want the 5th.
let ...
2
votes
2answers
176 views
Bash: passing braces as arguments to bash function
I love using the following pattern for searching in files:
grep --color=auto -iRnHr --include={*.js,*.html,} --exclude-dir={release,dev,} "span" .
I'd like, however, to have this one wrapped into a ...