http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-7.html
for i in $( ls ); do
echo item: $i
done
for i in `seq 1 10`;
do
echo $i
done
COUNTER=0
while [ $COUNTER -lt 10 ]; do
echo The counter is $COUNTER
let COUNTER=COUNTER+1
done
COUNTER=20
until [ $COUNTER -lt 10 ]; do
echo COUNTER $COUNTER
let COUNTER-=1
done
http://tldp.org/LDP/abs/html/loops1.html
for arg in [list] ; do
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_09_01.html
for i in `cat list`; do cp "$i" "$i".bak ; done
for i in "$LIST"; do
http://www.cyberciti.biz/faq/bash-for-loop/
for i in {1..5}
for i in {0..10..2}
The seq command (outdated)
for i in $(seq 1 2 20)
Three-expression bash for loops syntax
for (( c=1; c<=5; c++ ))
do
echo "Welcome $c times"
done
How do I use for as infinite loops?
for (( ; ; ))
http://code.tutsplus.com/tutorials/how-to-customize-the-command-prompt--net-20586
PS1='->'
source ~/.bashrc
PROMPT_COMMAND='echo "comes before the prompt"'
print_before_the_prompt () {
echo "$USER: $PWD"
}
PROMPT_COMMAND=print_before_the_prompt
http://compositecode.com/2014/10/09/bashit-just-a-custom-bash-prompt-setup-for-git/
https://medium.com/@mandymadethis/pimp-out-your-command-line-b317cf42e953
alias sub=’open -a “Sublime Text”’
http://stackoverflow.com/questions/20296664/how-to-uninstall-bash-it
http://mywiki.wooledge.org/BashFAQ/001
while IFS= read -r line; do
printf '%s\n' "$line"
done < "$file"
In the scenario above IFS= prevents trimming of leading and trailing whitespace. Remove it if you want this effect.
while read -r line; do
printf '%s\n' "$line"
done <<< "$var"
while read -r line; do
printf '%s\n' "$line"
done <<EOF
$var
EOF
while read -r line; do
[[ $line = \#* ]] && continue
printf '%s\n' "$line"
done < "$file"
# Input file has 3 columns separated by white space.
while read -r first_name last_name phone; do
# Only print the last name (second column)
printf '%s\n' "$last_name"
done < "$file"
# Extract the username and its shell from /etc/passwd:
while IFS=: read -r user pass uid gid gecos home shell; do
printf '%s: %s\n' "$user" "$shell"
done < /etc/passwd
For tab-delimited files, use IFS=$'\t'.
read -r first last junk <<< 'Bob Smith 123 Main Street Elk Grove Iowa 123-555-6789'
some command | while read -r line; do
printf '%s\n' "$line"
done
find . -type f -print0 | while IFS= read -r -d '' file; do
mv "$file" "${file// /_}"
done
Note the usage of -print0 in the find command, which uses NUL bytes as filename delimiters; and -d '' in the read command to instruct it to read all text into the file variable until it finds a NUL byte. By default, find and read delimit their input with newlines; however, since filenames can potentially contain newlines themselves, this default behaviour will split up those filenames at the newlines and cause the loop body to fail. Additionally it is necessary to set IFS to an empty string, because otherwise read would still strip leading and trailing whitespace.
http://mywiki.wooledge.org/IFS
IFS = input field separator
In the read command, if multiple variable-name arguments are specified, IFS is used to split the line of input so that each variable gets a single field of the input. (The last variable gets all the remaining fields, if there are more fields than variables.)
When performing WordSplitting on an unquoted expansion, IFS is used to split the value of the expansion into multiple words.