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???? |
Try read "X"
|
thank you
when i get home i will try it. Just curious what does the quotation marks do to the Read Command? |
I don't know about your particular situation but I use the quotes to make a command include spaces.
|
"" didnt work. Here is my script file.
Quote:
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 |
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. |
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" |
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. |
All times are GMT -5. The time now is 04:48 PM. |