The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
please explain the below mail2sant Shell Programming and Scripting 1 04-04-2008 05:04 AM
Please can any one explain this ${0##/} gadege Shell Programming and Scripting 2 04-01-2008 12:26 PM
please explain this dummy_needhelp Shell Programming and Scripting 2 10-14-2007 10:17 PM
if [ $? -eq 0 ] .. can someone explain this? ranjita.c Shell Programming and Scripting 5 10-03-2006 04:50 PM
Explain awk hitmansilentass Shell Programming and Scripting 4 09-27-2006 11:14 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-26-2007
Registered User
 

Join Date: Feb 2007
Posts: 7
Stumble this Post!
Can anyone explain plz

HI,

Can anyone explain to me how does the following command work - >

current_dir=`cd \`/usr/bin/dirname $0\` && pwd`

Regards,
Ranga
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-26-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Stumble this Post!
Code:
$ cat spt
echo $0
current_dir=`cd \`/usr/bin/dirname $0\` && pwd`
echo "current_dir="$current_dir
$ /db2home/training/anbu/spt
/db2home/training/anbu/spt
current_dir=/db2home/training/anbu
cd \`/usr/bin/dirname $0\` cd to script directory
pwd assign the directory to current_dir where script resides.

Instead of above code you can use this
Code:
current_dir=`/usr/bin/dirname $0`

Last edited by anbu23; 03-27-2007 at 12:04 AM.
Reply With Quote
  #3 (permalink)  
Old 03-27-2007
Registered User
 

Join Date: Feb 2007
Posts: 7
Stumble this Post!
Help needed

Hi ,

Thanks for your reply. One more doubt

Does “cd \`/usr/bin/dirname $0\` cd to script directory” will the same change the directory or jus gives u the directory name?

Regards,
Ranga
Reply With Quote
  #4 (permalink)  
Old 03-27-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Stumble this Post!
cd \`/usr/bin/dirname $0\` just change directory

In the following code this cd is done within `..` which will open new shell and change directory. So if you come out this line you will be in the same directory as before executing this line.
Code:
current_dir=`cd \`/usr/bin/dirname $0\` && pwd`
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:35 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0