|
Using $0 and 'Function' Keyword
Hi all,
I had a query on the usage of $0 in shells. I would appreciate any assistance in this.
We moved from a sun solaris server to a linux server. I ran 2 different pieces on these servers and in one case, the outputs didnt change and in the other case, the outputs were different. The 2 pieces involved defining functions differently.
Case #1
----------------------------------
#!/bin/ksh
echo "Value of $0 outside"
function callme2
{
echo "Value of $0 inside"
}
callme2
----------------------------------
Case #2
----------------------------------
#!/bin/ksh
echo "Value of $0 outside"
callme2()
{
echo "Value of $0 inside"
}
callme2
----------------------------------
Sun solaris output was the same in both cases, as given below.
Value of test.ksh outside
Value of test.ksh inside
But, the linux server gave different outputs.
case #1 output
Value of .//test.ksh outside
Value of callme2 inside
case #2 output
Value of .//test.ksh outside
Value of .//test.ksh inside
Can someone assist me in understanding why these differences exist inspite of the shell remaining the same and also what can be done to prevent this from occurring.
Thank you very much for your time...!!
|