{"id":554,"date":"2021-02-10T12:00:00","date_gmt":"2021-02-10T17:00:00","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=554"},"modified":"2021-02-03T02:31:35","modified_gmt":"2021-02-03T07:31:35","slug":"bash-using-positional-parameter","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/bash-using-positional-parameter\/","title":{"rendered":"Bash: using positional parameter"},"content":{"rendered":"\n<p>Positional parameters are used to pass arguments to a command line application. This post shows you how to used positional parameter in bash.<\/p>\n\n\n\n<p>On your terminal, type the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cal -y 2012<\/code><\/pre>\n\n\n\n<p>This command would print the calendar for 2012. -y and 2012 are positional paramters. Positional parameters are used to pass arguments to the program. The arguments become available to program as numbered parameters. In the above command, the arguments are passed as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$0 = cal\n$1 = -y\n$2 = 2012<\/code><\/pre>\n\n\n\n<p>Following example prints the positional parameters:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n#: Title \u00a0 \u00a0 \u00a0 : using positional parameter\n#: Description : show how to print and use positional parameters\n#: Options \u00a0 \u00a0 : war and year\n#: Example \u00a0 \u00a0 : $ .\/upp.sh WWII 1445\n\nprintf \"Filename: %s\\n\" \"$0\"\nprintf \"First Argument: %s\\n\" \"$1\"\nprintf \"Second Argument: %s\\n\" \"$2\"\nprintf \"%s ended in %s\\n\" \"$1\" \"$2\"<\/code><\/pre>\n\n\n\n<p>Type the following command to run the code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ .\/upp.sh WWII 1945<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Filename: upp.sh\nFirst Argument: WWII\nSecond Argument: 1945\nWWII ended in 1945<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Positional parameters are used to pass arguments to a command line application. This post shows you how to used positional parameter in bash. On your terminal, type the following command: This command would print the calendar for 2012. -y and 2012 are positional paramters. Positional parameters are used to pass arguments to the program. The [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101,34],"tags":[94,35],"class_list":["post-554","post","type-post","status-publish","format-standard","hentry","category-bash","category-linux","tag-bash","tag-linux"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/554","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=554"}],"version-history":[{"count":2,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/554\/revisions"}],"predecessor-version":[{"id":556,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/554\/revisions\/556"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=554"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=554"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=554"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}