Bash resources
To work productively on a linux platform, it's essential to learn a few bash tricks to improve productivity and efficiency.
Rules of bash variable expansion:
• Parameter expansion means that we could use other shell variables in this
expression, as in: ${BASE:=${HOME}}.
• Tilde expansion means that we can use expressions like ~bob and it will expand
that to refer to the home directory of the username bob. Use ${BASE:=~uid17} to
set the default value to the home directory for user uid17, but don’t put quotes
around this string, as that will defeat the tilde expansion.
• Command substitution is what we used in the example; it will run the commands
and take their output as the value for the variable. Commands are
enclosed in the single parentheses syntax, $( cmds ).
• Arithmetic expansion means that we can do integer arithmetic, using the $(( ... ))
syntax in this expression. Here’s an example:
echo ${BASE:=/home/uid$((ID+1))}
References:
1. My Favorite bash Tips and Tricks
http://www.linuxjournal.com/article/7385
2. Power shell usage: bash tips and tricks
http://www.ukuug.org/events/linux2003/papers/bash_tips/index.html
3. Discover best bash and bash sites
http://www.blinklist.com/tag/bash/
4. http://geeki.wordpress.com/category/bash/
5. http://devmanual.gentoo.org/tools-reference/bash/index.html
Rules of bash variable expansion:
• Parameter expansion means that we could use other shell variables in this
expression, as in: ${BASE:=${HOME}}.
• Tilde expansion means that we can use expressions like ~bob and it will expand
that to refer to the home directory of the username bob. Use ${BASE:=~uid17} to
set the default value to the home directory for user uid17, but don’t put quotes
around this string, as that will defeat the tilde expansion.
• Command substitution is what we used in the example; it will run the commands
and take their output as the value for the variable. Commands are
enclosed in the single parentheses syntax, $( cmds ).
• Arithmetic expansion means that we can do integer arithmetic, using the $(( ... ))
syntax in this expression. Here’s an example:
echo ${BASE:=/home/uid$((ID+1))}
References:
1. My Favorite bash Tips and Tricks
http://www.linuxjournal.com/article/7385
2. Power shell usage: bash tips and tricks
http://www.ukuug.org/events/linux2003/papers/bash_tips/index.html
3. Discover best bash and bash sites
http://www.blinklist.com/tag/bash/
4. http://geeki.wordpress.com/category/bash/
5. http://devmanual.gentoo.org/tools-reference/bash/index.html
<< Home