Saturday, October 10, 2009

Order of execution for /etc/profile .bash_profile .bash_login .profile /etc/bash.bashrc .bashrc

If interactive login-shell or non-interactive login shell with --Login option is started, it will start reading & executing in the order /etc/profile, .bash_profile, .bash_login and finally .profile

If interactive shell, that is a non-login shell is started, it will start reading & executing in the order /etc/bash.bashrc, .bashrc

Difference between .profile and .bashrc

.profile will be read, whenever login-shell is started

.bashrc will be read, whenever new interactive shell(not a login shell) is started

Monday, August 24, 2009

How to compress multiple files using tar and gzip

1. Put all the required filenames in a file
2. tar all the files
3. gzip the tar file
eg:
vjsujay@gmail.com$ ls *.html > filelist
vjsujay@gmail.com$ fname=filelist
vjsujay@gmail.com$ tar -cvf multihtml.tar -L $fname
vjsujay@gmail.com$ gzip multihtml.tar
Final file will be multihtml.tar.gz

Monday, July 20, 2009

To display only the user directories in Unix or Linux

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.

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

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)