Passing command line parameters to script
So far, we have seen the usage of the commands such as grep
, head
, ls
, cat
, and many more. These commands also support passing arguments to a command via a command line. Some of command line arguments are input files, output files, and options. Arguments are provided as per output needs. For example, ls -l filename
is executed to get a long listing output, while ls -R filename
is used to display recursively the contents of a directory.
Shell script also supports providing command line arguments that we can process further by a shell script.
The command line arguments can be given as follows:
<script_file> arg1 arg2 arg3 … argN
Here, script_file
is a shell script file to be executed, and arg1
, arg2
, arg3 ...
Get Linux Shell Scripting Essentials now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.