Posts

Showing posts with the label bash

Bash scripting tips

Bash is almost a complete programming language, I use every day (switching from the default tcsh in the servers, in Mac OS X is default) for automatic job launching. Extracted from: http://hacktux.com/bash/script/efficient. Avoid full paths to bash built-ins. Except when you require specific commands, when I use systems with 32 or 64b binaries, I need to specify which one to use, or define an specific directory to use in the PATH or as a variable. Avoid external commands for integer math. Because bash has math evaluation. Avoid using cat . Commonly people use cat and send to other commands with a pipe, but many commands can read files in the parameters. Avoid piping grep to awk . Because awk can filter the inputs, use /pattern/ Avoid piping sed to sed . Multiple filters can be applied to the input with the -e option ( sed -e "s/this/that/" -e "s/old/new/" filename ). Use double brackets for compound and RegEx tests. [[ ]] evaluate the operations between...