Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2003
    Posts
    6

    Red face Unanswered: 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.

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650

    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.

  3. #3
    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.

  4. #4
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    To determine mount point, use result of 'df -k .'
    Jean-Pierre.

  5. #5
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1

    Re: URGENT : Current directory when executing script from another volume

    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}"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •