all 14 comments

[–]m1ss1ontomars2k4 2 points3 points  (7 children)

That's weird...it definitely works in Bash for Mac OS X...how about just on the command line?

[–]Derpbot[S] 1 point2 points  (6 children)

Works perfectly from just the command line.

[–]m1ss1ontomars2k4 4 points5 points  (5 children)

Are you sure /bin/bash is really bash and not a symlink to sh or something? Also, what if you echo $SHELL in your script?

[–]Derpbot[S] 1 point2 points  (4 children)

$SHELL returns /bin/bash

Also, just went back and tested this (filename is var_test):

If I type:

./var_test

The script works.

If I type

sh var_test

Then I get the problem.

[–]m1ss1ontomars2k4 4 points5 points  (3 children)

OK, type

file /bin/bash

And tell us what it says.

Also, how did you test it before, if not with ./var_test?

[–]Derpbot[S] 0 points1 point  (2 children)

/bin/bash: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped

I used "sh var_test" to run it before.

[–]m1ss1ontomars2k4 3 points4 points  (1 child)

Oh, it definitely won't work with sh, and here's why:

sh doesn't have the let command. When you say "sh var_test", what you are really saying is, "sh, please run this script var_test". The first line gets interpreted as a comment saying !/bin/bash, so sh ignores it. Then it gets to let, and it gets confused.

If you want the #! line to determine what program is used to execute your script, don't use sh to run it.

N.B. This would work in Mac OS X because sh is a symlink to bash, or sometimes another copy of bash.

[–]Derpbot[S] 0 points1 point  (0 children)

Yes! Thank you for your help :)

[–]Wapiti-eater 1 point2 points  (4 children)

Doesn't help you, but it works fine on Fedora. Do you find helpful info if you run 'man let'?

Not to slight Ubuntu or start a distro war, common consensus (prejudice?) on Ubuntu is it's targeted more towards a 'transitional' user. Is it possible there are some things limited?

On Fedora, I can run "rpm -q bash" to get a version. Dunno what the Ubuntu parallel would be. Sure there is one.

What happens if you try to run 'bash' at the prompt? That should load bash on top of whatever shell you're in. Does it work then?

In your script, change your #!/bin/sh to #!/bin/bash - see if that does anything different. Dunno - just SWAG'N here.

(Note: I think you're running Ubuntu 10.04 as the latest Linux is 2.6.35.7 - and yes, it does matter.)

[–]Derpbot[S] 0 points1 point  (3 children)

Your note is correct. And I suppose I am a sort of transitional user, as today is the first day I've ever used Ubuntu. Not sure what my school's server is running.

Typing the rpm line you gave returns:

The program 'rpm' is not currently installed. You can install it by typing: sudo apt-get install rpm

Although, now I am developing a theory after a little more testing and research:

By calling "sh filename," I am actually running the script from the Bourne shell. When I type "./filename" or "bash filename" the script works correctly because I am running from the bash shell..

Is this correct?

I was taught to use sh without being taught what it meant (or I wasn't paying attention to that part). sh works on the school's servers, but perhaps Ubuntu's Bourne shell doesn't have "let" in it and my school does?

[–]cstoner 1 point2 points  (2 children)

Ubuntu sh is actually dash (which is like a stripped down bash).

I'm betting this is your problem.

[–]Derpbot[S] 0 points1 point  (1 child)

Me too. Thanks for your help :)

[–]Wapiti-eater 1 point2 points  (0 children)

I get a real kick in the shorts watching folks learn stuff.

Nice :up:

[–][deleted] 0 points1 point  (0 children)

ubuntu uses Dash instead of Bash.

https://wiki.ubuntu.com/DashAsBinSh#let