Tag: Date command displays case false cmd put who bar input
Shell Exercise: Write a script to do the following: Enter a number, and then run the corresponding command. The command is displayed as follows: *cmd meau** 1--date 2--ls 3--who 4--pwd When input 1 o'clock, the date command is run, and the input 2 o'clock will run LS to
Answer:
#! /bin/bashread-p "*cmd meau** 1--date 2--ls 3--who 4--pwd:" AIF (($a ==1)), Thendateelif (($a ==2)), Thenlselif (($a ==3)); Nwhoelif (($a ==4)) Thenpwdelseecho "Please input 1-4" fi
Answer 2:
#! /bin/bashecho "*cmd meau**" echo "1--date" echo "2--ls" echo "3--who" echo "4--pwd" read-p "please input a num:" Ncase $n in 1) date;; 2) LS; 3) who;; 4) pwd;; *) echo "please input 1-4";; Esac
Answer 3:
#! /bin/bashecho "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 Exercise: Write a script to do the following: Enter a number, and then run the corresponding command. The display command is as follows: *cmd