通过实例讲解 Bash 脚本的基本知识
Resources:
- http://en.wikipedia.org/wiki/Shebang_(Unix)
- http://www.gnu.org/software/bash/manual/bash.html#Command-Substitution
- http://linuxcommand.org/tlcl.php
#!/usr/bin/env bashfor i in `ls`do echo $idone
#!/usr/bin/env bashecho "Number of arguments: $#The program name is: $0The first argument is: $1"
#!/usr/bin/env bash
if [ $# != 1 ]then echo """Error: missing operandUsage: ./delete_or_not.sh PATHNAME """ >&2 exit 1fi
cd $1for file in `ls`do echo -n "Want to delete:$file ? (Y/n): " read AAA if [ "${AAA:-y}" = "y" ];then echo delete $file rm $file echo ...done else echo pass fidone