Shell command line parameters
Most Linux command can take different actions depending on the command line arguments supplied to the command.
What is a command line argument?
A command line argument is nothing but an argument sent to a program being called. A program can take any number of command line arguments. For example, type the following command:
grate_stories_of: No such file or directory.
ls is the name of an actual command and shell executed this command when you type command at shell prompt. The first word on the command line is:
- ls - name of the command to be executed.
- Everything else on command line is taken as arguments to this command.
Consider the following example:
tail +10 /path/to/file.txt
- tail : command name.
- +10 /path/to/file.txt : The arguments.
Try the following command and note down its command line arguments:
|Command||Command name||Total number of arguments||Argument name(s)|
|cp /etc/resolv.conf /tmp/test.txt||cp||2||/etc/resolv.conf, and /tmp/test.txt|
|sort -r -n /path/to/file||sort||3||-r, -n, and /path/to/file|
Command line parameters different names
A Command line parameter also known as:
- Command line options
- Positional parameters
- Switches or switch
- Command-line arguments
Why use command line arguments
- Telling the command/utility which option to use.
- Informing the utility/command which file or group of files to process (reading/writing of files).