Nelson Green grabbed a keyboard and wrote:
>
> Good morning,
>
> Can anyone help me understand why the following two console commands each
> produce output, but only one of them produces output when both are called in a
> shell script?
>
> $ /bin/echo "Shell: $SHELL"
> Shell: /bin/bash
> $ /bin/echo "Random: $RANDOM"
> Random: 29707
>
> $ 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).
--Dave
Attachment:
signature.asc
Description: OpenPGP digital signature