LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash scripting: filenames with spaces (https://www.linuxquestions.org/questions/programming-9/bash-scripting-filenames-with-spaces-326571/)

joanq 05-24-2005 08:01 AM

bash scripting: filenames with spaces
 
Hello,

here is a simple script I use to show how "select" works:

#!/bin/bash
OPTIONS="Quit `ls`"
PS3="Which file do you want to know more about? "
select op in $OPTIONS
do
if [ "$op" = "Quit" ]; then
echo "See you!"
exit 0
else
file "$op"
fi
done

But this has a problem when a filename has spaces. It appears on the menu like two diferent options instead of one. I tried to use "ls -Q" or "ls -b" to protect these names, but it doesn't work.

Do you know how to solve it?

Thanks in advance,

JoanQ

Hko 05-24-2005 10:51 AM

Code:

#!/bin/bash

PS3="Which file do you want to know more about? "
select op in Quit * ; do
  if [ "$op" = "Quit" ]; then
          echo "See you!"
          exit 0
  else
          file "$op"
  fi
done


joanq 05-24-2005 12:50 PM

Thanks Hko!

It was easy but I didn't think of it...


All times are GMT -5. The time now is 11:40 PM.