LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-24-2005, 08:01 AM   #1
joanq
LQ Newbie
 
Registered: Oct 2003
Distribution: Debian
Posts: 6

Rep: Reputation: 0
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
 
Old 05-24-2005, 10:51 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
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
 
Old 05-24-2005, 12:50 PM   #3
joanq
LQ Newbie
 
Registered: Oct 2003
Distribution: Debian
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks Hko!

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Spaces in filenames with BASH edenning Programming 12 01-27-2005 07:10 AM
bash and filenames with spaces doctorwebbox Linux - General 2 12-15-2004 08:55 PM
bash, loops and spaces in filenames shy Programming 5 11-08-2004 07:43 AM
Scripting question reg. filenames with spaces Awfki Linux - Newbie 3 05-16-2004 08:01 PM
BASH scripting problem, spaces in filenames / using basename textures Programming 24 11-16-2003 01:41 AM


All times are GMT -5. The time now is 07:54 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration