hi grepFruit,
thanks for replying, but i want the script to run on all machines, so i dont think so i'll be able to use "readlink" (i found that its not working on SunOS 5.10).
---------- Post updated at 07:18 PM ---------- Previous update was at 06:54 PM ----------
hi ygemici,
thnx for replying,
with the suggestion provided i am able to get absolute script path when i run script from the directoy where it is situated i.e. using ./test.sh.
# cat test.sh
currentpath="`pwd`/"
currentscript=`echo $0 | sed 's/^[./]*//'`
echo "currentscript : $currentscript"
echo "script name: $currentpath$currentscript"
but my real concern is in situation where i run script using ../ as in following case
# pwd
/my/test1
bash-3.00# ../test/dir/test.sh
currentscript : test/dir/test.sh
script name: /my/test1/test/dir/test.sh
bash-3.00#
scriptname should have been "/my/test/dir/test.sh"
got what you are doing,
"`dirname \"$0\"`" is a relative path, but still its a valid path from current pwd. so you are jumping to that path, then get new pwd in variable, which will give me what i want. and then jump back to old pwd where i wad initially.
I was looking for that trick by long time, thanks for the post.
Just a silly question ... i thought that that command in backticks `command` was equivalent with command like this $( command ) but ..ehm.. i realized now that's not really the same. I tested the alister's trick with $( command ) instead of backticks.. but no success.
So what's the real difference between `command` and $( command ) please?
In short, using the old style, obsolete backtick syntax can get hairy when used within double quotes and/or when you try to nest command substitutions. The newer syntax, $(...) parses commands just as if they were the top-level, without any special quoting requirements (sooooo much nicer).