Bash notes
From Noah.org
Jump to navigationJump to search
Contents
Turn off bash history for a session
set +o history
Variable Expansion and Substitution
Bash can do some freaky things with variables. It can do lots of other substitutions. See "Parameter Expansion" in the Bash man page.
- ${foo#pattern} - deletes the shortest possible match from the left
- ${foo##pattern} - deletes the longest possible match from the left
- ${foo%pattern} - deletes the shortest possible match from the right
- ${foo%%pattern} - deletes the longest possible match from the right
- ${foo=text} - If $foo exists and is not null then return $foo. If $foo doesn't exist then create it and set value to text.
Statements
Loop on filenames in a directory
for foo in *; do { echo ${foo} }; done
Loop on lines in a file
for foo in $(cat data_file.txt); do { echo ${foo} }; done