User Tools

Site Tools


bash:commands:command_line_arguments

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
bash:commands:command_line_arguments [2021/01/26 17:00] – [BASH - Commands - Command Line Arguments] peterbash:commands:command_line_arguments [2021/01/26 17:03] (current) peter
Line 3: Line 3:
 Getting arguments directly from the command shell can be beneficial in a number of cases. Getting arguments directly from the command shell can be beneficial in a number of cases.
  
-<code bash>+<file bash test.sh>
 #!/bin/bash #!/bin/bash
 echo "Total arguments : $#" echo "Total arguments : $#"
 echo "First Argument = $1" echo "First Argument = $1"
 echo "Second Argument = $2" echo "Second Argument = $2"
-</code>+</file>
  
 Run this script with two additional parameters after its name. Run this script with two additional parameters after its name.
- 
-I’ve named it test.sh and the calling procedure is outlined below. 
  
 <code bash> <code bash>
Line 31: Line 29:
 The below example shows how to get command-line arguments with their names. The below example shows how to get command-line arguments with their names.
  
-<code bash>+<file bash test.sh>
 #!/bin/bash #!/bin/bash
  
Line 50: Line 48:
  
 echo "X+Y=$result" echo "X+Y=$result"
-</code>+</file>
  
-Name this script test.sh and call it as shown below.+Run this script with two additional parameters after its name.
  
 <code bash> <code bash>
Line 58: Line 56:
 </code> </code>
  
-It should return X+Y=144.+returns 
 + 
 +<code bash> 
 +X+Y=144 
 +</code> 
 + 
 +<WRAP info> 
 +**NOTE:**  The arguments here are stored inside **‘$@‘** and the script fetches them using the Linux **cut** command. 
 +</WRAP>
  
-The arguments here are stored inside ‘$@‘ and the script fetches them using the Linux cut command. 
  
bash/commands/command_line_arguments.1611680415.txt.gz · Last modified: 2021/01/26 17:00 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki