#!/bin/bash
# handle the command's parameters
# shell's name is test
cli="test"
while [ $# -gt 0 ] # $# means the number of the parameters and $* means the parameter's string
do
case $1 in # $1 means the first parameter
-f)
cli=$cli" -f "
shift # shift means remove the leftmost parameter
cli=$cli"$1"
shift
;;
-d)
cli=$cli" -d "
shift
cli=$cli"$1"
shift
;;
esac
done
echo $cli
本文介绍了一个简单的Shell脚本示例,该脚本演示了如何处理命令行参数。通过使用while循环和case结构,脚本能够识别并处理-f和-d选项及其对应的参数。

1万+

被折叠的 条评论
为什么被折叠?



