!/bin/bash

echo -e "Your name is ==> $(whoami)"
echo -e "The current directory is ==> $(pwd)"

  • 请自行创建一支程序,该程序可以用来计算“你还有几天可以过生日”啊?

!/bin/bash

  • 让使用者输入一个数字,程序可以由 1+2+3… 一直累加到使用者输入的数字为止。

!/bin/bash

read -p "Please input an integer number: " number
i=0
s=0
while [ "$i" != "$number" ]
do
i=$(($i+1))
s=$(($s+$i))
done
echo "the result of '1+2+3+…$number' is ==> $s"

!/bin/bash

  • 我们知道 /etc/passwd 里面以 : 来分隔,第一栏为帐号名称。请写一只程序,可以将 /etc/passwd 的第一栏取出,而且每一栏都以一行字串“The 1 account is "root" ”来显示,那个 1 表示行数。

!/bin/bash

accounts=cat /etc/passwd | cut -d':' -f1
for account in $accounts
do
declare -i i=$i+1
echo "The $i account is \"$account\" "
done