Sunday, August 2, 2009

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.

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


Command No. of argument to this command (i.e $#) Actual Argument
ls 1 foo
cp 2 y and y.bak
mv 2 y.bak and y.okay
tail 2 -10 and myf
mail 1 raj
sort 3 -r, -n, and myf
date 0
clear 0

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

More command on one command line

To run two command with one command line.

$ date;who
Will print today's date followed by users who are currently login. Note that You can't use
$ date who
for same purpose, you must put semicolon in between date and who command.

Wild cards (Filename Shorthand or meta Characters)
Why Command Line arguments required
Post a Comment

You might also like :

Related Posts with Thumbnails