Bash scripting tidbits
If you had a variable called PART and wished to use it in a string by doing echo 1000$PART1 it will simple echo 1000, as bash will think its variable PART1. To get around this one would use echo 1000${PART}1, enclosing the variable name in braces.
For extended if conditions, use [[ ]]. This allows for complex boolean expressions, and also removes the need to type test. For example:
if [[ -f $file1 && -f $file2 && $file1 != $file2 ]];
The exit code of the last executed command is stored in $?, and should exit be called with out an argument, it will return with the exit code of the last command.
Finally, integer comparisons are via -ne, -eq, -lt, -gt while string comparisons are via =, != etc..
Cheers,
Steve
0 Comments:
Post a Comment
<< Home