vjsujay@home$ ls -lA "pipeline symbol" grep '^d'
drwxr-s--- 2 n0160429 ccipadm 512 Jul 21 00:17 .temp
drwxr-s--- 2 n0160429 ccipadm 512 Mar 15 04:58 cal
drwxr-s--- 2 n0160429 ccipadm 512 May 06 04:50 dump
drwxr-s--- 2 n0160429 ccipadm 512 May 05 23:14 script
drwxr-s--- 2 n0160429 ccipadm 512 Jul 18 12:28 temp
Note: If you use ls -la means, you will get . (dot) and .. (dot dot) directory also.
Monday, July 20, 2009
To display only the user directories in Unix or Linux
Saturday, July 18, 2009
Difference between single square and double square brackets in conditional check in shell scripting
1. [ conditional check ] -> Variables used in the conditional check should have value, otherwise exception will be thrown during the execution.
2. [[ cond check ]] -> Exception will not thrown, even if variable don't have value or not received any value during the execution.
So, it is advisable to use single square bracket always to ensure whether we are receiving the value and doing the conditional checking.
example:
echo "Enter your name: "
read NAME
if [[ $NAME == "sujay" ]]
then
echo Your name is $NAME
else
echo Your name is $NAME from else part
fi
$ ksh doublesquare.sh
Enter your name:
sujay
Your name is sujay
$ ksh doublesquare.sh
Enter your name:
Your name is from else part
Note: If double square bracket is replaced with single: if [ $NAME == "sujay" ]
$ ksh singlesquare.sh
Enter your name:
sujay
Your name is sujay
$ ksh singlesquare.sh
Enter your name:
singlesquare.sh[4]: test: 0403-004 Specify a parameter with this command.
Your name is from else part
2. [[ cond check ]] -> Exception will not thrown, even if variable don't have value or not received any value during the execution.
So, it is advisable to use single square bracket always to ensure whether we are receiving the value and doing the conditional checking.
example:
echo "Enter your name: "
read NAME
if [[ $NAME == "sujay" ]]
then
echo Your name is $NAME
else
echo Your name is $NAME from else part
fi
$ ksh doublesquare.sh
Enter your name:
sujay
Your name is sujay
$ ksh doublesquare.sh
Enter your name:
Your name is from else part
Note: If double square bracket is replaced with single: if [ $NAME == "sujay" ]
$ ksh singlesquare.sh
Enter your name:
sujay
Your name is sujay
$ ksh singlesquare.sh
Enter your name:
singlesquare.sh[4]: test: 0403-004 Specify a parameter with this command.
Your name is from else part
Friday, July 17, 2009
Different type of Command Substitution in Shell Scripting
In two ways we can do the command substitution.
1.) Using backquote: ``
2. Using dollar sign and parenthesis: $()
eg:
vjsujay@home $ echo My system name is `uname -n`
vjsujay@home $ echo My system name is $(uname -n)
1.) Using backquote: ``
2. Using dollar sign and parenthesis: $()
eg:
vjsujay@home $ echo My system name is `uname -n`
vjsujay@home $ echo My system name is $(uname -n)
Subscribe to:
Posts (Atom)