randomized lines
hi
i am trying to createa a randomized number and then when number is picked by the randomizer it shows a line.. when you do !test in the game.. it should give a randomized line. it recognizes !test command but it says script is wrong.. script : Code:
#!/bin/sh Quote:
anyone an idea or solution for my problem :( |
You need a quotation mark before test3.
Hope this helps. |
Probably
echo test3" is missing a " It should be: echo "test3" |
change line 12 from
echo test3" to echo "test3" |
i tried it.. but still it gives me that error.. :(
|
Ok guys, look at this:
Code:
#!/bin/sh But replace /bin/sh with /bin/bash or /bin/ksh and it does. You have to know the syntax of the shell you specified... :) |
Quote:
If you are running bash, it doesn't matter because it doesn't really look at the first line (one of bash oddities). So this works on a lot of default install. It works on my machine. If you are running another one like "dash" then it will look at the first line (shebang). |
that's what my next line says ..... depends on which shell you use.
Note that (for those who don't know) on Linux sh is often symlinked to bash, but that won't always happen. In production environments, you should ALWAYS specify the shell to be used, just in case the SW is installed under a user whose default shell turns out to be different. |
Unfortunatly your 2 posts and mine are not clear enough..
Better: It depends on which shell calls this script :) |
I could be wrong, but I think that's only true if a cmd shell is NOT specifed as the first line.
Otherwise, i think the parent shell (or kernel?) will try to use the shell specified ... Actually, that happened today at work. Tried to run a script that specified #!/bin/ksh, but it turned out that the local version was in /usr/bin/ksh |
You can explicitely tell what shell to use, as in:
source ./script.sh or /bin/ksh ./script.sh Else the shell used will be the one told on the first line. As said above, on Linux, /bin/sh is often an alias for /bin/bash; however /bin/bash, when called as sh, changes its inner workings to be closer to the behaviour of the old original sh. In your case, $((...)) is a bash-only feature, hence the problem you had. However this line can be "standardized" with the expr command. Yves. |
Quoth theYinYeti:
Quote:
Code:
#!/bin/sh |
That's because of what I said, you are running bash.
This script is a "bashism". It will only work for people who have /bin/sh pointing to /bin/bash, I have /bin/sh linked to /bin/dash so it doesn't work. Whereas the "source", it's a bit different: it executes in the current shell, so it does not spawn a new shell, see this example. Take care ;) Code:
#!/bin/sh |
You're right wjevans! The man page changed since I read about this issue back in the early '90. Now it reads like this:
<<When invoked as sh, bash enters posix mode after the startup files are read.>> and I suppose $((...)) is posix. I stand corrected. Yves. |
True $(( works on dash too
I should have checked maybe :) These one only work (as expected) in bash: echo "test" &> /tmp/u echo d{a,b,c} echo $(( $RANDOM % 3 )) ...etc |
All times are GMT -5. The time now is 05:27 PM. |