bash:commands:command_line_arguments
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
bash:commands:command_line_arguments [2021/01/26 17:00] – [BASH - Commands - Command Line Arguments] peter | bash: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 " | echo " | ||
- | </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 " | echo " | ||
- | </code> | + | </file> |
- | Name this script | + | Run this script |
<code bash> | <code bash> | ||
Line 58: | Line 56: | ||
</ | </ | ||
- | It should return | + | returns |
+ | |||
+ | <code bash> | ||
+ | X+Y=144 | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | </ | ||
- | 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