通过实例讲解 Bash 脚本的基本知识

到 B 站观看视频

Resources:

#!/usr/bin/env bash
for i in `ls`
do
    echo $i
done
#!/usr/bin/env bash
echo "
Number of arguments: $#
The program name is: $0
The first argument is: $1
"
#!/usr/bin/env bash

if [ $# != 1 ]
then
    echo """
Error: missing operand
Usage: ./delete_or_not.sh PATHNAME
         """ >&2
    exit 1
fi

cd $1
for 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
    fi
done