[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: unexpected script output



[You know, it would be *really* nice if you set your mail program to
include an attribute line at the top, indicating who you're replying
to/quoting.... :-)]

Nelson Green grabbed a keyboard and wrote:
> [I said...]
>> Nelson Green grabbed a keyboard and wrote:
>>> $ cat output.sh
>>> #!/bin/sh
>>> /bin/echo "Shell: $SHELL"
>>> /bin/echo "Random: $RANDOM"
>>>
>>> $ sh output.sh
>>> Shell: /bin/bash
>>> Random:
>>>
>>> Why is there no output from the call to $RANDOM in the script?
>>
>> 'Cause /bin/sh points to dash, not bash, in Debian.
>>
>> $ ls -la /bin/sh
>> lrwxrwxrwx 1 root root 4 Nov 20 07:44 /bin/sh -> dash*
>>
>> Change your shebang line to #!/bin/bash to make it work right and then
>> set the executable bit on the script. Then you can just do ./output.sh
>> to get the expected results (don't do "sh output.sh," since that will
>> just invoke /bin/sh which points you back to dash).
> 
> Oops, I thought I had already linked /bin/sh to /bin/bash, but I hadn't. I do
> not like dash, and I have to use bash on a lot of non-Debian systems, so I try
> to keep my environment as similar as I can all the way around.
> 
> Thanks Dave!

Glad I was able to help.

BTW, if you want to avoid that particular pitfall in the future, don't
use $SHELL - that's a variable that reflects your *default* shell.  If
you want to see what the current shell environment is for what you're
running, use $0 instead.

$ echo $0 $SHELL
-bash /bin/bash
$ exec tcsh
> echo $0 $SHELL
tcsh /bin/bash

HTH.

                  --Dave


Attachment: signature.asc
Description: OpenPGP digital signature


Reply to: