Linux Shell Scripting Tutorial (LSST) v1.05r3
Prev
Chapter 2: Getting started with Shell Programming
Next

Command Line Processing

Try the following command (assumes that the file "grate_stories_of" is not exist on your system)
$ ls grate_stories_of
It will print message something like - 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. Now it creates one more question What are commands? What happened when you type $ ls grate_stories_of ?

The first word on command line is, ls - is name of the command to be executed.
Everything else on command line is taken as arguments to this command. For e.g.
$ tail +10 myf
Name of command is tail, and the arguments are +10 and myf.

Exercise
Try to determine command and arguments from following commands
$ ls foo
$ cp y y.bak
$ mv y.bak y.okay
$ tail -10 myf
$ mail raj
$ sort -r -n myf
$ date
$ clear

Answer:

Command No. of argument  to this command (i.e $#)Actual Argument
ls1foo
cp2y  and   y.bak
mv2y.bak and  y.okay
tail2-10  and  myf
mail1raj
sort3-r, -n, and myf
date0 
clear0 

NOTE:
$# holds number of arguments specified on command line. And $* or $@ refer to all arguments passed to script.


Prev
Home
Next
More commands on one command line
Up
Why Command Line arguments required