The function tag has no wiki summary.
2
votes
1answer
135 views
Why do Unix-like systems execute a new process when calling a new function?
Why do Unix-like systems execute a new process when calling a function rather than a dynamic library? Creating a new process is costly in terms of performance when compared to calling a dynamic ...
2
votes
0answers
103 views
How to enable `sudo` with custom functions?
Recently I learned you can enable sudo for custom aliases as follows:
alias sudo='sudo ' # note: the space is required!
The reason this works is the following:
If the last character of the ...
0
votes
1answer
25 views
How to understand the result returned by “nm” command
I used nm command to inspect the function names in a .so library.
And the result I got is like this:
00009634 T _Z24ICTCLAS_ParagraphProcessPKciPc9eCodeTypeb
00009764 T ...
4
votes
4answers
217 views
How can I pass a command line argument into a shell script?
I know that shell scripts just run commands as if they were executed in at the command prompt. I'd like to be able to run shell scripts as if they were functions... That is, taking an input value or ...
1
vote
2answers
83 views
Script to create files in a template
I just wrote a function in my ~/.bashrc that will let me create a folder for a new website with one command. The function looks like this:
function newsite() {
mkcd "$*" # mkdir and cd into it
...
41
votes
8answers
1k views
In Bash, when to alias, when to script, and when to write a function?
It's taken me almost 10 years of Linux usage to ask this question. It was all trial and error and random late-night internet surfing.
But people shouldn't need 10 years for this. If I were just ...
7
votes
7answers
191 views
Doing simple math on the command line using bash functions: $1 divided by $2 (using bc perhaps)
Sometimes I need to divide one number by another. It would be great if I could just define a bash function for this. So far, I am forced to use expressions like
echo 'scale=25;65320/670' | bc
but ...
6
votes
2answers
118 views
How do I redefine a bash function in terms of old definition?
Is there any way I can redefine a bash function in terms of its old definition? For example I would like to add the following block of code to the preamble of the function command_not_found_handle (),
...
1
vote
3answers
123 views
What does the “(8)” in fsck(8) mean?
*nix commands (and functions?) have a number with them, like fsck(8), killall(1), etc.
What does the number mean?
1
vote
3answers
179 views
Can I “export” functions in bash?
source some_file
some_file:
doit ()
{
echo doit $1
}
export TEST=true
If I source some_file the function "doit" and the variable TEST are available on the command line. But running this script:
...
3
votes
3answers
245 views
How to pass a string parameter on bash function?
I have this code that does work:
get_parameter ()
{
echo "$query" | sed -n 's/^.*name=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"
}
But I want to replace the "name" with the parameter that I pass ...
4
votes
2answers
126 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 ...
2
votes
2answers
217 views
creating simple command for sudo apt-get install?
I need to run these commands very often:
sudo apt-get install <package>
sudo apt-get remove <package>
Can I make it simple like:
install <package>
remove <package>
I ...
2
votes
3answers
126 views
Prefix every argument with -o in BASH
How do I prefix -p to every argument passed to my function?
Modifying the arguments themselves and creating a new array are both fine.
4
votes
4answers
222 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 ...