LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-05-2004, 03:44 PM   #1
Kilahchris
Member
 
Registered: Jan 2003
Location: NY
Distribution: Suse 9.0
Posts: 202

Rep: Reputation: 30
how to make the Read command handles spaces


I wrote a simple script for TuxNes emulator (Nintendo emulator).

The script works with loading files with names where there is no spaces in between the characters.


for example (Because i dont have access to my computer my script is much longer and doesnt look exactly like this)


!#Bin Bash

echo Which game would you like to play?

Read X;

if [-n, x]

tuxnes --video=1024x768 -- <some other options> $X;

else

echo No such game.






when I enter a game like Superman the game properly loads from the script. However when i enter a game like Super Mario Bros i get either file not found or

when I get the prompt which Game you would like to play?
sometimes I enter Super/ Mario/ Bros/ 3* and i get an error too many arguments.???


Does anyone know how to make the bash read command accept spaces that are in what you input????
 
Old 11-05-2004, 04:04 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Try read "X"
 
Old 11-05-2004, 04:18 PM   #3
Kilahchris
Member
 
Registered: Jan 2003
Location: NY
Distribution: Suse 9.0
Posts: 202

Original Poster
Rep: Reputation: 30
thank you

when i get home i will try it. Just curious what does the quotation marks do to the Read Command?
 
Old 11-05-2004, 04:30 PM   #4
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
I don't know about your particular situation but I use the quotes to make a command include spaces.
 
Old 11-05-2004, 04:35 PM   #5
Kilahchris
Member
 
Registered: Jan 2003
Location: NY
Distribution: Suse 9.0
Posts: 202

Original Poster
Rep: Reputation: 30
"" didnt work. Here is my script file.



Quote:
#!/bin/bash

ls
echo "Which game would you like to play"


read -r "X"

if [ -n "$X" ];

then


tuxnes --renderer=auto --geometry=1024x768 --format=16 --sound=/dev/audio --soundrate=44100 --js1=/dev/js0 --enlarge=12 --joystick-map=B1,B0,B10,B9,A0,A1,A2,A3 $X

else

echo "no such file found"

fi;


Does anyone know which bash command will accept input with spaces between characters?
Is there a way to make the Read command accept spaces such as in file names like
Super Mario Bros (U).nes



Last edited by Kilahchris; 11-05-2004 at 08:39 PM.
 
Old 11-06-2004, 07:31 AM   #6
Darin
Senior Member
 
Registered: Jan 2003
Location: Portland, OR USA
Distribution: Slackware, SLAX, Gentoo, RH/Fedora
Posts: 1,024

Rep: Reputation: 45
I don't belive that was where he was talking about using the quotes, try it when you input the name:

$> ./tuxnes.sh
Which game would you like to play?
"Super Mario Brothers"

If that doesn't work you may have to insert surrounding quotes or escape the spaces inside the variable X. My guess is that if X is "super mario" then the command:

tuxnes $X

would try to run on both words like two seperate options, as if you typed:

tuxnes super
tuxnes mario

If you could do something like $X = quotes + $X + quotes then the command would work although I can't for the life of me think of the right syntax that would add the quote symbol into the beginning and end of a variable.
 
Old 11-06-2004, 10:19 AM   #7
LasseW
Member
 
Registered: Oct 2004
Distribution: Fedora 7, OpenSuse 10.2
Posts: 108

Rep: Reputation: 15
Yes, the quotes do work, but you need to use them in the argument list of the tuxnes command as well, ie the end of the command should read

joystick-map ... "$X"
 
Old 11-06-2004, 12:10 PM   #8
Kilahchris
Member
 
Registered: Jan 2003
Location: NY
Distribution: Suse 9.0
Posts: 202

Original Poster
Rep: Reputation: 30
ok thanks for all your input.


He was right.

All i needed to do was type put quotes around Read "X" variable, quotes does not need to be around the what input

and once I copy and paste the filename it ran. I was simply able to type Super Mario Bros 3 (E) and everything worked.


The reason why i didnt work before because i was trying to make thinks easier by using the asterix sign like

Super Mario Bros 3*
instead of typing the full name of the file.

Last edited by Kilahchris; 11-06-2004 at 12:21 PM.
 
  


Reply



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
how to make a tab is 4 spaces width in vim? ICO SUSE / openSUSE 8 03-05-2013 10:24 AM
I accidentally deleted make file in /usr/local/bin, now cannot use make command.... Niceman2005 Linux - Software 2 11-17-2004 07:55 PM
Why do I get spaces in my CLASSPATH when I set it in make? SheldonPlankton Programming 2 09-27-2004 08:48 PM
Spaces on command line odd Linux - Software 2 05-22-2004 08:17 AM
how do I make a read-only file NOT read-only? robster Linux - General 1 02-17-2004 09:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration