Re: basic bash help

From: Maxim Demenko <mdemenko_at_gmail.com>
Date: Fri, 27 May 2011 21:49:45 +0200
Message-ID: <4DE00059.6050907_at_gmail.com>



On linux it can be done relatively simple this way:

 >cat whatami
#!/bin/bash
echo $(readlink -f $0)
 >./whatami
/home/oracle/whatami

Best regards

Maxim

On 27.05.2011 21:26, Radoulov, Dimitre wrote:
> On 27/05/2011 20:42, Stephens, Chris wrote:

>>
>> I'm writing a script to allow the sysadmin's to kill any active 
>> sessions for a particular database user.
>>
>> If the script is called as root, I re-invoke it as oracle.  However, 
>> 'dirname' doesn't seem to be working as expect and I have no idea why 
>> or how to get around it.  A little bit of googl'ing didn't help 
>> either so I turn to old faithful. J
>>
>>

> [...]
>

> You could use something like this (assuming a *POSIX* shell):
>
>

> SCRIPT_DIR=$(
> cd -P -- "$(dirname -- "$0")" && pwd -P
> )
>
>

> It won't work if you invoke the script as:
>

> sh script_name
>

> and the script is not in the current directory.
>

> In that case you could use something like this:
>
>

> SCRIPT_DIR=$(
> _script=$0
> case $_script in
> ( */* ) ;;
> ( * ) [ -e "$_script" ] || _script=$(command -v -- "$0")
> esac
> cd -P -- "$(dirname -- "$_script")" && pwd -P
> )
>
>
>

> It won't work in all situations, but it may be sufficient :)
>
>

> Regards
> Dimitre

>
>
--
http://www.freelists.org/webpage/oracle-l
Received on Fri May 27 2011 - 14:49:45 CDT

Original text of this message