90 likes | 207 Views
Lab # 10. Shell Script con. while loop. Syntax : while [ condition ] do command1 command2 command3 .. .... done. while loop. The case Statement. Syntax : case $variable-name in pattern1) command ... command;; pattern2) command
E N D
Lab # 10 Shell Script con.
while loop Syntax: while [ condition ] do command1 command2 command3 .. .... done
The case Statement Syntax: case $variable-name in pattern1) command ... command;; pattern2) command ... command;; patternN) command ... command;; *) command ... command;; esac
Write shell script using for loop to print the following patterns . 122333444455555 for (( i=1; i<=5; i++ )) do for (( j=1; j<=i; j++ )) do echo -n "$i" done echo ”“ done
Write script to print numbers as 5,4,3,2,1, using while loop. The biggest number is supplied as command line argument. i=$1 while test $i != 0 do echo –n "$i ," i=`expr $i - 1` done echo " "
Write script to implement get options statement, your script should understand following command line argument :script-name -c -d -m –eWhere options work as-c clear the screen-l show list of files in current working directory-h display history file-d display the date
if [ $# -ne 1 ] then echo " Enter one argument –c , –l , –h or -d" else case $1 in " -c ") clear;; " -l ") ls -l;; " -h ") history;; " -d ") date ;; *) echo " Invalid option ";; esac fi