I have a executable shell script name project2. Following is one of the instruction my teacher gave me on the project.
This script must accept at least one
command line parameter: the directory
where its output is to be placed. If
that directory is not given on the
command line, the script should use a
reasonable default directory.
Can you please tell me how can I make my script accept a command line. I haven’t done anything like that before. Any help would be greatly appreciated. Thanks a lot.
For
bash, command line parameters are stored in$1,$2, and so on, while$#will give you the count. In addition,shiftcan be used to shift them all “left” by one position and drop the count.The following script is a good starting point for understanding how the parameters work:
When you run it with:
the output is:
The basic idea of your assignment is: