标签:date命令 显示 case false cmd put who bar 输入
shell练习:写一个脚本实现如下功能:输入一个数字,然后运行对应的一个命令。显示命令如下:*cmd meau** 1--date 2--ls 3--who 4--pwd 当输入1时,会运行date命令,输入2时会运行ls,以此论推答案:
#! /bin/bash read -p "*cmd meau** 1--date 2--ls 3--who 4--pwd:" a if (($a==1));then date elif (($a==2));then ls elif (($a==3));then who elif (($a==4));then pwd else echo "please input 1-4" fi
答案2:
#! /bin/bash echo "*cmd meau**" echo "1--date" echo "2--ls" echo "3--who" echo "4--pwd" read -p "please input a num:" n case $n in 1) date ;; 2) ls ;; 3) who ;; 4) pwd ;; *) echo "please input 1-4" ;; esac
答案3:
#! /bin/bash echo "1-date 2--ls 3--who 4--pwd" read -p "cmd meau" n [ $n -eq 1 ] && date [ $n -eq 2 ] && ls [ $n -eq 3 ] && who [ $n -eq 4 ] && pwd
shell练习:写一个脚本实现如下功能:输入一个数字,然后运行对应的一个命令。显示命令如下:*cmd
标签:date命令 显示 case false cmd put who bar 输入
原文地址:http://blog.51cto.com/12129628/2061093