korn script

korn script

am 27.09.2007 23:14:12 von sonal10july

Hi Friends,

Following is the content of a file which is used to start the
server.I'm just pasting two lines of the script which I'm not
understanding.

sea1suasp06:/opt/rep1501/REP-15_0/install $ more /REP-12_1/install/
RUN_rep06

#!/bin/ksh -p
typeset _PROG=${0##*/}
typeset _client=${_PROG##*_}


I will be thankful if any anybody can explain me what these above two
lines are doing ?


Thanks
Son

Re: korn script

am 27.09.2007 23:30:13 von Janis Papanagnou

sonal10july@gmail.com wrote:
> Hi Friends,
>
> Following is the content of a file which is used to start the
> server.I'm just pasting two lines of the script which I'm not
> understanding.
>
> sea1suasp06:/opt/rep1501/REP-15_0/install $ more /REP-12_1/install/
> RUN_rep06
>
> #!/bin/ksh -p
> typeset _PROG=${0##*/}

$0 contains the script name, optionally with the path. ${0##*/} removes
the longest (##) matching pattern of arbitrary characters (*) until a
dash (/). So any file/path like /home/sonal/bin/a_b.sh will result
in the name of the script a_b.sh (in this example). The name is then
assigned to the variable _PROG, and typeset is a kornshell variable
declaration.

> typeset _client=${_PROG##*_}

Similar to the above, but instead of operating on $0 it operates on the
variable _PROG, and instead of stripping all characters until the last
dash it does so until an underscore (_). With the above example you will
get the resulting name b.sh

Janis

> I will be thankful if any anybody can explain me what these above two
> lines are doing ?
>
>
> Thanks
> Son
>

Re: korn script

am 28.09.2007 01:05:38 von sonal10july

On Sep 27, 5:30 pm, Janis Papanagnou
wrote:
> sonal10j...@gmail.com wrote:
> > Hi Friends,
>
> > Following is the content of a file which is used to start the
> > server.I'm just pasting two lines of the script which I'm not
> > understanding.
>
> > sea1suasp06:/opt/rep1501/REP-15_0/install $ more /REP-12_1/install/
> > RUN_rep06
>
> > #!/bin/ksh -p
> > typeset _PROG=${0##*/}
>
> $0 contains the script name, optionally with the path. ${0##*/} removes
> the longest (##) matching pattern of arbitrary characters (*) until a
> dash (/). So any file/path like /home/sonal/bin/a_b.sh will result
> in the name of the script a_b.sh (in this example). The name is then
> assigned to the variable _PROG, and typeset is a kornshell variable
> declaration.
>
> > typeset _client=${_PROG##*_}
>
> Similar to the above, but instead of operating on $0 it operates on the
> variable _PROG, and instead of stripping all characters until the last
> dash it does so until an underscore (_). With the above example you will
> get the resulting name b.sh
>
> Janis


Thank You so much Janis !!
I got it perfectly.

There is one more question here
In your example earlier , two things are happening

1. /home/sonal/a_b.ksh ======>> a_b.ksh
2. a_b.ksh ======>> b.ksh

Suppose, if there is change in naming convention
for eg
a_b.ksh becomes a_0b.ksh
a_c.ksh becomes a_0c.ksh
a_d.ksh becomes a_0d.ksh

Basically after underscore a additional zero is added in each file

So, now I want

a_0b.ksh ==> b.ksh
a_0c.ksh ==> c.ksh

What changes we need to make in the above variables ?

Re: korn script

am 28.09.2007 02:36:48 von Janis Papanagnou

sonal10july@gmail.com wrote:
> On Sep 27, 5:30 pm, Janis Papanagnou
> wrote:
>
>>sonal10j...@gmail.com wrote:
>>
>>>Hi Friends,
>>
>>>Following is the content of a file which is used to start the
>>>server.I'm just pasting two lines of the script which I'm not
>>>understanding.
>>
>>>sea1suasp06:/opt/rep1501/REP-15_0/install $ more /REP-12_1/install/
>>>RUN_rep06
>>
>>>#!/bin/ksh -p
>>>typeset _PROG=${0##*/}
>>
>>$0 contains the script name, optionally with the path. ${0##*/} removes
>>the longest (##) matching pattern of arbitrary characters (*) until a
>>dash (/). So any file/path like /home/sonal/bin/a_b.sh will result
>>in the name of the script a_b.sh (in this example). The name is then
>>assigned to the variable _PROG, and typeset is a kornshell variable
>>declaration.
>>
>>
>>>typeset _client=${_PROG##*_}
>>
>>Similar to the above, but instead of operating on $0 it operates on the
>>variable _PROG, and instead of stripping all characters until the last
>>dash it does so until an underscore (_). With the above example you will
>>get the resulting name b.sh
>>
>>Janis
>
>
>
> Thank You so much Janis !!
> I got it perfectly.
>
> There is one more question here
> In your example earlier , two things are happening
>
> 1. /home/sonal/a_b.ksh ======>> a_b.ksh
> 2. a_b.ksh ======>> b.ksh
>
> Suppose, if there is change in naming convention
> for eg
> a_b.ksh becomes a_0b.ksh
> a_c.ksh becomes a_0c.ksh
> a_d.ksh becomes a_0d.ksh
>
> Basically after underscore a additional zero is added in each file
>
> So, now I want
>
> a_0b.ksh ==> b.ksh
> a_0c.ksh ==> c.ksh
>
> What changes we need to make in the above variables ?
>

typeset _client=${_PROG##*_0}

The pattern is * for arbitrary characters up to the last "_0".

Janis