1819802 Members
3042 Online
109607 Solutions
New Discussion юеВ

Re: Variable Syntax

 
SOLVED
Go to solution
Franz P
Advisor

Variable Syntax

I just set up a HA NFS ServiceGuard package. The controlfile contains a line:
HA_NFS_SCRIPT="${0%/*}/hanfs.${HA_NFS_SCRIPT_EXTENSION:-sh}"

What does "${0%/*}" stand for? I asked a few guys but nobody knows.

If I run something like
#!/bin/sh
echo ${0%/*}

I get a ".", but if it means just . I would write ./hanfs.blahblah.
Does anybody understand what I am talking about!? ;-)
5 REPLIES 5
Ernesto Cappello
Trusted Contributor

Re: Variable Syntax

Hi Franz, i don't know what does "${0%/*}".
You can look this "sh" script for variables example:

#!/bin/sh
echo "$#:" $#
echo '$#:' $#
echo '$-:' $-
echo '$?:' $?
echo '$$:' $$
echo '$!:' $!
echo '$3:' $3
echo '$0:' $0
echo '$*:' $*
echo '$@:' $@

If you execute it, obtain:

$ ./variables.sh one two three four five
5: 5
$#: 5
$-:
$?: 0
$$: 12417
$!:
$3: three
$0: ./variables.sh
$*: one two three four five
$@: one two three four five

Best regards,
Ernesto
Heiner E. Lennackers
Respected Contributor
Solution

Re: Variable Syntax

Hi Franz,

this will take the argument of $0 ( the name of your program including path ) and removes the last / and everything behind it.

for example:
./program -> .
/usr/bin/test -> /usr/bin

You can look into the manpage of your shell (e.g. man ksh) for details.

HeL
if this makes any sense to you, you have a BIG problem
Heiner E. Lennackers
Respected Contributor

Re: Variable Syntax

Sorry, not the argument, the value of $0 :)

${parameter%pattern}
${parameter%%pattern}
If the shell pattern matches the end of the
value of parameter, the value of parameter
with the matched part is deleted; otherwise
substitute the value of parameter. In the
former, the smallest matching pattern is
deleted; in the latter, the largest matching
pattern is deleted.
if this makes any sense to you, you have a BIG problem
Ivan Krastev
Honored Contributor

Re: Variable Syntax

See "Pattern-Matching Operators" - http://www.oreilly.com/catalog/korn2/chapter/ch04.html


regards,
ivan
Franz P
Advisor

Re: Variable Syntax

Thank you guys, your help is very appreciated! Even after 15yrs in IT you learn new features every day... :-0