WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: /usr/bin/select shell script menu TC 4.6.1 and TC 5.2  (Read 4714 times)

Offline KHarvey

  • Full Member
  • ***
  • Posts: 102
/usr/bin/select shell script menu TC 4.6.1 and TC 5.2
« 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
Code: [Select]
/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:
Code: [Select]
#!/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.

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: /usr/bin/select shell script menu TC 4.6.1 and TC 5.2
« Reply #1 on: May 30, 2014, 04:32:03 PM »
bash is /usr/local/bin/bash, not /bin/bash.

Offline KHarvey

  • Full Member
  • ***
  • Posts: 102
Re: /usr/bin/select shell script menu TC 4.6.1 and TC 5.2
« Reply #2 on: May 30, 2014, 05:27:31 PM »
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.

Offline Greg Erskine

  • Sr. Member
  • ****
  • Posts: 404
Re: /usr/bin/select shell script menu TC 4.6.1 and TC 5.2
« Reply #3 on: May 30, 2014, 08:10:48 PM »
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

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: /usr/bin/select shell script menu TC 4.6.1 and TC 5.2
« Reply #4 on: May 30, 2014, 09:33:58 PM »

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.
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline KHarvey

  • Full Member
  • ***
  • Posts: 102
Re: /usr/bin/select shell script menu TC 4.6.1 and TC 5.2
« Reply #5 on: May 31, 2014, 08:39:53 PM »

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.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11049
Re: /usr/bin/select shell script menu TC 4.6.1 and TC 5.2
« Reply #6 on: June 01, 2014, 04:25:34 AM »
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.
The only barriers that can stop you are the ones you create yourself.