The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

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 08:04 AM
Please can any one explain this ${0##/} gadege Shell Programming and Scripting 2 04-01-2008 03:26 PM
please explain this dummy_needhelp Shell Programming and Scripting 2 10-15-2007 01:17 AM
if [ $? -eq 0 ] .. can someone explain this? ranjita.c Shell Programming and Scripting 5 10-03-2006 07:50 PM
Explain awk hitmansilentass Shell Programming and Scripting 4 09-27-2006 02:14 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-27-2007
r_W213 r_W213 is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 7
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
  #2 (permalink)  
Old 03-27-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
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 03:04 AM..
  #3 (permalink)  
Old 03-27-2007
r_W213 r_W213 is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 7
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
  #4 (permalink)  
Old 03-27-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
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`
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:59 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0