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

RE: unexpected script output



> 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

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!

PS, I'm getting ready to post a request for help in capturing the output of time
to a script variable. I can't seem to make it work despite many different 
attempts. I don't think that's a dash issue, but if you know that it is, let me
know.
 		 	   		  

Reply to: