Tagged Questions
4
votes
2answers
95 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 ...
4
votes
1answer
142 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, ...
7
votes
4answers
970 views
Executing user defined function in a find -exec call
I'm on Solaris 10 and I have tested the following with ksh (88), bash (3.00) and zsh (4.2.1).
The following code doesn't yield any result:
function foo {
echo "Hello World"
}
find somedir -exec ...
2
votes
2answers
93 views
Is there any way I can fit this into my ~/.bashrc as a function?
I just discovered this useful bit of code on this useful-looking website.
#!/bin/sh
exec tclsh "$0" ${1+"$@"}
proc main {} {
set lines [lrange [split [read stdin] \n] 0 end-1]
set count ...
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
4answers
467 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 ...
87
votes
9answers
5k 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 ...
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 ...
2
votes
2answers
601 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 ...