Re: Finding absolute path of a script from within
Jeenu wrote:
> On Mar 14, 5:45 pm, Florian Kaufmann <sensor...@gmail.com> wrote:
>>> where_am_i=$((cd $(dirname $0) && pwd))
>>> Or is there any other/easier way?
>> How about
>>
>> where_am_i=$(dirname $0)
>
> Yeah, that's what I initially tried in my script. If my script is
> executed like
> ./my_script
> OR like
> ../../dir/myscript
> where_am_i will only contain "." and "../../dir" respectively which
> are not absolute
How about:
cd $(dirname $0) && DIR="$PWD" && cd - >/dev/null
echo $DIR
--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.
|