Tagged Questions
12
votes
4answers
513 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
2answers
68 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 ...
2
votes
1answer
48 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 ...
2
votes
3answers
160 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 ...
4
votes
2answers
252 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
167 views
Function caller positional parameters
I need to read and write the positional parameters $@ of a function's caller. The Bash man page says that:
A shell function is an object that is called like a simple command and
executes a ...
2
votes
1answer
150 views
awk function with a number parameter for the column you want to print
I want to use my awk shortcut as a function, so that I can pass the column number which then prints me the output. My aliases are:
alias A="| awk '{print \$1}'
alias G="| grep -i'
Instad of typing:
...
2
votes
1answer
65 views
Restoring an option at the end of a function in zsh
I'm writing a zsh shell function (as opposed to a script) where I would really like the extended_glob option to be enabled. But since the function runs in the caller's context, I don't want to clobber ...
4
votes
2answers
198 views
Combine two commands in .bash_profile
In my .bash_profile file, I'd like to setup a single command alias that is two commands that execute one after another. The first command takes an argument from the command line and the second is ...
-1
votes
2answers
256 views
calling functions within a function
I need to fetch the results of different time ranges and email the results, but i am having trouble with the email part of the script,
how can i send an email with both results? (15min range and ...
4
votes
4answers
486 views
Is it possible to source a file in bash, but skipping specific functions?
Suppose I have bash_functions.sh:
function test(){
}
function test2(){
}
And in my ~/.bashrc I do:
source ~/bash_functions.sh
Is it possible to, when sourcing it, avoid sourcing a specific ...
10
votes
1answer
907 views
bash functions vs scripts
This site says, "Shell functions are faster [than aliases]. Aliases are looked up after functions and thus resolving is slower. While aliases are easier to understand, shell functions are preferred ...