
在 ifelseifelse.sh 文件中,
#!/bin/bash
if [ ${1,,} = herbert ]; then
echo "Oh, you're the boss here. Welcome!"
elif [ ${1,,} = help ]; then
echo "Just enter your username, duh!"
else
echo "I don't know who you are. But you're not the boss of me!"
fi

在 admin.sh文件中,
#!/bin/bash
case ${1,,} in
herbert | administrator)
echo "Hello, you're the boss here!"
;;
help)
echo "Just enter your username!"
;;
*)
echo "Hello there. You're not the boss of me. Enter a valid username!"
esac


for item in ${MY_FIRST_LIST[@]}; do echo -n $item | wc -c; done
输出为:
3
3
5
4
4
for item in ${MY_FIRST_LIST[@]}; do:这是一个for循环的开始,它将遍历名为MY_FIRST_LIST的数组中的所有元素。$item表示当前遍历到的数组元素。
echo -n $item:这部分命令用于打印(显示)当前数组元素的值,但-n选项表示不要在末尾添加换行符。这意味着它会把元素值输出在同一行。
|:这是管道符号,它将前一个命令的输出传递给后一个命令作为输入。
wc -c:这部分命令使用wc命令来统计字符数(字节数)。-c选项告诉wc只统计字符数,而不是单词数或行数。
“;”:这是命令分隔符,它用于将多个命令放在同一行。
done:这是for循环的结束标记,表示循环体的结束。
在firstfunction.sh中,
#!/bin/bash
showuptime(){
local up=$(uptime -p | cut -c4-)
local since=$(uptime -s)
cat << EOF
-----
This machine has been up for ${up}
It has been running since ${since}
-----
EOF
}
showuptime
输出为:

在 functionposargu.sh 文件中,
#!/bin/bash
showname(){
echo hello $1
}
showname Herbert

在 functionposargu.sh 文件中,
#!/bin/bash
showname(){
echo hello $1
if [ ${1,,} = herbert ]; then
return 0
else
return 1
fi
}
showname $1
if [ $? = 1 ]; then
echo "Someone unknown called the function!"
fi
