利用shift对每个参数进行操作

脚本: 

#!/bin/bash
if [ $# -eq 0 ]
then
  echo "usage:bash $0 x x x; (x:pwd ls date)"
fi

while [ $# -gt 0 ]
do
  case $1 in
      "pwd")
        pwd
        ;;
      "ls")
        ls
        ;;
      "date")
        date
        ;;
      *)
        echo "请输入这里面的参数:pwd ls ll"
        ;;
  esac
  shift
done

运行结果:

猜你喜欢

转载自blog.csdn.net/weixin_53308294/article/details/129650608