{"id":3367,"date":"2014-07-21T23:00:58","date_gmt":"2014-07-21T15:00:58","guid":{"rendered":"http:\/\/rmohan.com\/?p=3367"},"modified":"2014-07-21T23:00:58","modified_gmt":"2014-07-21T15:00:58","slug":"command-line-argument-in-shell-script","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=3367","title":{"rendered":"Command line argument in shell script"},"content":{"rendered":"<p>Command line argument in shell script<br \/>\nPassing arguments to the main program when it start is know as command line arguments<br \/>\nIn shell scripting arguments can be described like below<\/p>\n<p>$0 &#8211; shows program name which you running<br \/>\n$1 &#8211; shows first argument<br \/>\n$2 &#8211; display second argument<br \/>\n$3 &#8211; display third argument<br \/>\n$n &#8211; n th argument<br \/>\n$# &#8211; shows number of arguments passed to the program<br \/>\n$* &#8211; shows entire string of parameters you passed<\/p>\n<p>SCRIPT:<br \/>\n#!\/bin\/bash<br \/>\necho &#8220;programme name is $0&#8221;<br \/>\necho &#8220;first argument is $1&#8221;<br \/>\necho &#8220;Second argument is $2&#8221;<br \/>\necho &#8220;Total command line arguments is $#&#8221;<br \/>\necho &#8220;Entered arguments was :$*&#8221;<\/p>\n<p>RUN THE SCRIPT:<br \/>\n.\/cmd_arg.sh hi this is mohan<\/p>\n<p>OUTPUT:<br \/>\nprogramme name is .\/cmd_arg.sh<br \/>\nfirst argument is hi<br \/>\nSecond argument is this<br \/>\nTotal command line arguments is 4<br \/>\nEntered arguments was :hi this is mohan<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Command line argument in shell script Passing arguments to the main program when it start is know as command line arguments In shell scripting arguments can be described like below<\/p>\n<p>$0 &#8211; shows program name which you running $1 &#8211; shows first argument $2 &#8211; display second argument $3 &#8211; display third argument $n &#8211; [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3367"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3367"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3367\/revisions"}],"predecessor-version":[{"id":3368,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3367\/revisions\/3368"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}