Tiny Core Linux
Tiny Core Base => TCB Bugs => Topic started by: KHarvey on May 30, 2014, 03:33:31 PM
-
I'm attempting to write a shell script that prompts the user to select from a menu of choices. But I am unable to get the select statement to work. I keep receiving an error
/usr/bin/select: line xx: can't open in: no such file
xx in TC 4.6.1 is 54
xx in TC 5.2 is 62
I attempted to just use a basic script to make sure that it wasn't my convoluted code:
#!/bin/bash
OPTIONS="Hello Quit"
select opt in $OPTIONS; do
if [ "$opt" = "Quit" ]; then
echo done
exit
elif [ "$opt" = "Hello" ]; then
echo Hello World
else
clear
echo bad option
fi
done
But even that code fails with the same error.
I can probably write the same thing using if statements and accomplish the same thing. But I figured I would ask anyways.
Please note I have not tried any of this code on another distro, I have only tried it on TC.
-
bash is /usr/local/bin/bash, not /bin/bash.
-
Gah!
I was actually using /bin/sh for my script. The example that I posted above was copied and pasted from the website that I was using to test.
But if I use /usr/local/bin/bash then the script runs properly. I have a lot of scripts that I need to go change from /bin/sh to /usr/local/bin/bash.
Thanks for pointing out my error.
-
Gah!
I was actually using /bin/sh for my script. The example that I posted above was copied and pasted from the website that I was using to test.
But if I use /usr/local/bin/bash then the script runs properly. I have a lot of scripts that I need to go change from /bin/sh to /usr/local/bin/bash.
Thanks for pointing out my error.
Hi KHarvey,
You may not need to change all your scripts.
Although I have limited knowledge about the differences of shells, I believe it is because you wanted to use an array that you need to use the bash shell.
AFAIK sh does not support arrays directly.
regards
-
I have a lot of scripts that I need to go change from /bin/sh to /usr/local/bin/bash.
That sounds like really bad practice in two aspects:
1. Never ever use a bash header for portable shell scripts without explicit bashisms.
2. Never ever use #!/usr/local/bin/bash as header for bash scripts, but always #!/usr/bin/env bash.
-
I have a lot of scripts that I need to go change from /bin/sh to /usr/local/bin/bash.
That sounds like really bad practice in two aspects:
1. Never ever use a bash header for portable shell scripts without explicit bashisms.
2. Never ever use #!/usr/local/bin/bash as header for bash scripts, but always #!/usr/bin/env bash.
You're right. It has been so long since i have had to write a script like this I completely forgot about the difference between bash and shell scripts. This one is the only one that I actually need to change as it is the only one that uses arrays.
Also I did not know about using the #!/usr/bin/env bash. Is that a TC thing, or should that be used else where as well? In theory by the time I have to write another script like this I will have surely forgotten, but it is still worth noting somewhere.
-
It's a general thing, allowing for bash in anywhere in the path. Someone might have a newer bash in ~/mybash, added to their PATH, and that would find it.