12.8 本章习题
#!/bin/bash echo -e "Your name is ==> $(whoami)" echo -e "The current directory is ==> $(pwd)"#!/bin/bash read -p "Pleas input your birthday (MMDD, ex> 0709): " bir now=`date +%m%d` if [ "$bir" == "$now" ]; then echo "Happy Birthday to you!!!" elif [ "$bir" -gt "$now" ]; then year=`date +%Y` total_d=$(($((`date --date="$year$bir" +%s`-`date +%s`))/60/60/24)) echo "Your birthday will be $total_d later" else year=$((`date +%Y`+1)) total_d=$(($((`date --date="$year$bir" +%s`-`date +%s`))/60/60/24)) echo "Your birthday will be $total_d later" fi#!/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 if [ ! -e logical ]; then touch logical echo "Just make a file logical" exit 1 elif [ -e logical ] && [ -f logical ]; then rm logical mkdir logical echo "remove file ==> logical" echo "and make directory logical" exit 1 elif [ -e logical ] && [ -d logical ]; then rm -rf logical echo "remove directory ==> logical" exit 1 else echo "Does here have anything?" fi#!/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
Last updated