Sunday, January 30, 2011

BASH : Command Chaining and Command Lists

Command Chaining - multiple commands
'pwd; echo hello world' -> prints pwd and then prints 'hello world'
clear;pwd;echo hello world -> 3 commands in a row
clear;pwd;echo hello world;echo another line -> 4commands in a row
clear;cd /;ls -l;echo you are in $PWD;echo time to go back home;cd ~;echo you are now in $PWD; echo you were in $OLDPWD
set | grep $? -> list variables available


Command Lists: && - apersants; || - pipes
ls -l && pwd ->the second will execute only if the first returns status OK which is 0.
ls -l && echo you are now in $PWD
ls -l || echo you are now in $PWD -> the second will execute only if the first returns status FAILED which is 1.
ls -z || echo you are now in $PWD -> the echo will apear because the first command fails
ls -l && ls -z -> both runs and the second displays invalid option

No comments:

Post a Comment