Wednesday, January 29, 2014

Unix Shell Scripting - Line Command

- It is possible to run two or more Unix commands on the same line in a shell script, by separating the commands with ; (semicolon) character

[oracle@rac1 ~]$ echo Todays date is ;date
Todays date is
Thu Jan 30 08:45:08 IST 2014

- For aesthetic reasons if you wish to split the command into multiple lines, we can use single quotes, double quotes or back slash

Using Double Quotes:

[oracle@rac1 ~]$ echo "This is an example
> of command splitting
> across multiple
> lines"
This is an example
of command splitting
across multiple
lines

Using Single Quotes:

[oracle@rac1 ~]$ echo 'This is an example
> of command splitting
> across multiple
> lines'
This is an example
of command splitting
across multiple
lines

Using Backslash:

[oracle@rac1 ~]$ echo This is an example \
> of command splitting \
> across multiple \
> lines
This is an example of command splitting across multiple lines

Notice the difference for splitting the command using backslash, that’s the specialty of Backslash

No comments:

Post a Comment