Actually OP was so badly worded I didn't know what he wanted. It occurred to me that was what he wanted but I dismissed it.
My preference would be:The problem is when you invoke the code asPHP Code:
myname=${0##*/}
mydir=${0%/\*\}
you end up with mydir being null. You then have to add something likePHP Code:
sh myprog
And don't forget that if you invoke it with a relative path and then want to move to a different directory in the script ...PHP Code:
mydir=${mydir:-$PWD}
Basically what should happen is that mydir is set to something which is not null and then a subshell is invoked to go to the location of mydir and pass back the absolute path. But I haven't tested this so I may have it wrong.PHP Code:
#!/bin/bash
myname=${0##*/}
mydir=${0%/\*\}
mydir=${mydir:-$PWD}
mydir=$(cd $mydir; pwd -p)
printf "mydir is %s\n" $mydir
Andrew
Bookmarks