If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > URGENT : Current directory when executing script from another volume

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-03-04, 16:29
imsathya imsathya is offline
Registered User
 
Join Date: Oct 2003
Posts: 6
Red face URGENT : Current directory when executing script from another volume

Hello friends,

I am not very high-up on Shell scripting - so sorry if this is a stupid query.

I work on Mac OS X. I have another volume/disk mounted on my machine. I am trying to execute a script residing on that disk. The script is supposed to get the directory path where it is residing. I am using :

CURRENT_DIRECTORY=`pwd`
echo "CURRENT_DIRECTORY is $CURRENT_DIRECTORY"

But the result of this is coming out to be my machine's desktop where the volume is mounted. :

CURRENT_DIRECTORY is /Users/sathya

rather than the expected

CURRENT_DIRECTORY is /Volumes/Disk1/MyDirectory

I am executing the script from sh :

#!/bin/sh

Is this not the way to get the directory ?
Is there any other way I can get the path ?

Thanks.
Reply With Quote
  #2 (permalink)  
Old 02-03-04, 16:56
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,543
Re: URGENT : Current directory when executing script from another volume

can you do
df -k /users/sathya

and post it here ...

I assume you want something different and not `pwd`


Cheers
Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 02-04-04, 05:01
imsathya imsathya is offline
Registered User
 
Join Date: Oct 2003
Posts: 6
These is the output of the df -k :


[Sathyas-Panther-Jr:~/SFAScripts/TESTING] sathya% df -k
Filesystem 1K-blocks Used Avail Capacity Mounted on
/dev/disk0s5 58599900 30403184 27940716 52% /
<volfs> 512 512 0 100% /.vol
automount/Servers
automount -static [327] 0 0 0 100% /automount/static
/dev/disk1s2 662960 554544 108416 84% /Volumes/TestDisk

My problem is that I have a script I am executing residing on the mounted volume (/Volumes/TestDisk) on my machine (/dev/disk0s5). Now, when I try to get the current directory in the script :

CURRENT_DIR=`pwd`
echo $CURRENT_DIR

Instead of the expected /Volumes/TestDisk, it returns $HOME.

Any ideas ?

Thanks.
Reply With Quote
  #4 (permalink)  
Old 02-04-04, 05:40
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
To determine mount point, use result of 'df -k .'
__________________
Jean-Pierre.
Reply With Quote
  #5 (permalink)  
Old 02-05-04, 09:36
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,454
Re: URGENT : Current directory when executing script from another volume

Quote:
Originally posted by imsathya
Hello friends,

I am not very high-up on Shell scripting - so sorry if this is a stupid query.

I work on Mac OS X. I have another volume/disk mounted on my machine. I am trying to execute a script residing on that disk. The script is supposed to get the directory path where it is residing. I am using :

CURRENT_DIRECTORY=`pwd`
echo "CURRENT_DIRECTORY is $CURRENT_DIRECTORY"

But the result of this is coming out to be my machine's desktop where the volume is mounted. :

CURRENT_DIRECTORY is /Users/sathya

rather than the expected

CURRENT_DIRECTORY is /Volumes/Disk1/MyDirectory

I am executing the script from sh :

#!/bin/sh

Is this not the way to get the directory ?
Is there any other way I can get the path ?

Thanks.
try this:

#!/bin/bash

CURRENT_DIR=`dirname $0`

echo "\$CURRENT_DIR=${CURRENT_DIR}"
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On