The argument, also known as a command-line argument, can be defined as the input given to executable to process that input.
The argument can be simply a text. It can also be a name to a file or directory. Or it can be a predefined option particularly for that command.
Arguments are entered into the terminal or console after a command. When we give a command to the shell, the words separated by space after the actual command are known as the arguments.
$ <command> <argument> $ <command> <argument> <argument>
$ cd Downloads $ ls Documents $ cd /home/student/Desktop
The command “cd Downloads” has changed our directory to Downloads. Linux ls sample list down the contents in the Documents directory.
Here in the first command the text “Downloads” is an argument to cd executable. And in the second command “Documents” is an argument to ls executable.
The command “file example test2.txt” displays ‘example’ file type first and then ‘test2.txt’ file type. Here example and test2.txt are two arguments for the executable file.
White space removal
Linux white spaces are invisible but take up necessary memory area. While executing the command these white spaces are automatically get removed from the output.
Now we will use the “echo” command which is used to print the output that it receives from the shell.
Sample syntax of :
$ echo <typed-text>
$ echo welcome to example
In this command we get the output
$ welcome to example
Notice that, the space between echo and welcome got removed. This because arguments in the command line are identified as the words separated by space. Each word is treated as an argument. But NOT the space between them.
But when we need to change to a directory, which has a name with space, what we can do there? For example, we have a directory named “my photos”, how we can
cd in it?
Simple answer is to use the quotes. Or use the backward slash. Lets talk about the quotes.
Single and double quotes
If you want white spaces to be considered in an argument then use them within the quotes.
The shell allows a single as well as double-quotes. Any text within a quote is considered as a single argument. For example if we want to cd to “my photos”, then we could do:
$ cd “my photos”
$ cd ‘my photos’
Here my photos is a single argument passed to cd executable. If we don’t use the quotes, ‘my’ and ‘photos’ will be two arguments for the cd executable.
‘echo -e’ command is used with ‘\n’ and ‘\t’ to start a new line and add a tab space respectively. That works within a single as well as double-quotes.
$ echo -e 'welcome \tto \nLinux'
Notice the output, ‘\n’ displayed the output in a new line and ‘\t’ displayed the output with a tab space. A single and double quote displays the same output.