Presentation is loading. Please wait.

Presentation is loading. Please wait.

Presented by, Mr. Satish Pise

Similar presentations


Presentation on theme: "Presented by, Mr. Satish Pise"— Presentation transcript:

1 Presented by, Mr. Satish Pise
Experiment No. 9 Presented by, Mr. Satish Pise

2 Command Line Parameters ($1 $2 ..)
# sh addem 10 30 This example passes two command line parameters (10 and 30) to the script addem Example 1 #!/bin/bash # using one command line parameter value1=10 total=$[ $value1 * $1 ] echo $total

3 Example 2 #!/bin/bash # testing string parameters echo Hello $1, glad to meet you. # sh test3 satish

4 Example 3 #!/bin/bash # handling lots of parameters total=$[ ${10} * ${11} ] echo The tenth parameter is ${10} echo The eleventh parameter is ${11} echo The total is $total $ sh test

5 Counting parameters ($#)
Example 1 #!/bin/bash # getting the number of parameters echo There were $# parameters supplied. $ sh test8 There were 0 parameters supplied. $ sh test

6 Being Shifty Example 1 #!/bin/bash # demonstrating the shift command
count=1 while [ -n "$1" ] do echo "Parameter #$count = $1" count=$[ $count + 1 ] shift done $ sh test13 rich barbara katie jessica

7 Example 2 #!/bin/bash # demonstrating a multi-position shift echo "The original parameters: $*" shift 2 echo "Here’s the new first parameter: $1" $ sh test

8 Processing simple options
Example 1 #!/bin/bash # extracting command line options and values while [ -n "$1" ] do case "$1" in -a) echo "Found the -a option";; -b) param="$2" echo "Found the -b option, with parameter value $param" shift 2;; -c) echo "Found the -c option";; --) shift break;; *) echo "$1 is not an option";; esac shift done count=1 for param in echo "Parameter #$count: $param" count=$[ $count + 1 ] $ sh test17 -a -b test1 –d


Download ppt "Presented by, Mr. Satish Pise"

Similar presentations


Ads by Google