Proces the content of /etc/passwd file field by field

Here IFS sets the “internal field delimiter” to “:”, but only inside the while loop. You must NOT reset it to the original value.

while IFS=: read name passwd uid gid fullname ignore
do
  echo "$name ($fullname)"
done < ${TMP}   # I/O redirection.

Do some actions for secrtain files:

Comparison with shell

If you read “man test” you’ll note that the “=” comparison operator is for strings, while “-eq” is used for numerical comparisons.

If you want to get really fancy, you can also write your code as (not tested, so try at your own risk):

[ $choice -eq 1 -a $choice1 -eq 0 ] && while [ $target -ne 2 ] ; do

References

  1. http://www.linuxtopia.org/online_books/advanced_bash_scripting_guide/index.html
  2. Advanced Bash-Scripting Guide (also in PS, PDF, HTML). URL: http://www.tldp.org/LDP/abs/
Some ‘bash’ Magic
Tagged on:     

Leave a Reply