Interesting $0 Problem

jd1008 jd1008 at gmail.com
Fri Oct 28 02:21:28 UTC 2016


That's because your PATH variable first searched /usr/local/bin
so that is the name of the shell that is running.
For example, from the command line:
$ echo $0
-ksh

and my PATH variable looks like this:

$ echo $PATH
/sbin:/usr/sbin:/bin:/usr/bin:/usr/libexec:/usr/local/bin:/opt/bin:/opt/schily/bin/:
So, my entry in the password file says my shell is /bin/ksh
$ grep jd /etc/passwd
jd:x:108o:1080:jd:/home/jd:/bin/ksh

HTH.


On 10/27/2016 07:53 PM, Tim Daneliuk wrote:
> On 10/27/2016 08:49 PM, Dutch Ingraham wrote:
>> On Thu, Oct 27, 2016 at 08:30:40PM -0500, Tim Daneliuk wrote:
>>> I was fidding with some shell code today and discovered it was breaking
>>> because $0 was returning "-/usr/local/bin/bash".   Why is there a leading
>>> dash here?  I've not seen that before.
>> How are you invoking the expansion, i.e., from a file or the
>> command-line?  Is this a login shell?
>>
>> What do you get from the command-line with <echo "$0">?
>> _______________________________________________
>> freebsd-questions at freebsd.org mailing list
>> https://lists.freebsd.org/mailman/listinfo/freebsd-questions
>> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"
>>
>
> My .bashrc source as standard startup profile:
>
>    . mystartup
>
> Inside mystartup the folloing statement exists:
>
>    source foo.sh
>
> $0 as reported in foo.sh is coming back with "-/usr/local/bin/bash"...
>



More information about the freebsd-questions mailing list