LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   bash script ? -- spaces in passed parameters (https://www.linuxquestions.org/questions/linux-newbie-8/bash-script-spaces-in-passed-parameters-193132/)

azwr 06-13-2004 07:29 PM

bash script ? -- spaces in passed parameters
 
Hi, I'm fairly new to Linux, and trying to do some rudimentary bash scripting. Here's my problem, I'm writing a really simple bash script to run the mp3 encoder Lame with my normal command-line arguments (more as an experiment than a real necessity), and am having problems with I'm passing it command-line parameters with spaces involved. For instance, this command executed in a shell works just fine, where hde1 is my other hd still in Fat32 with windows installed as a dual-boot (barely used now),

lame --preset standard "/mnt/hde1/windows/desktop/from other hd/to encode.wav"

but this simple bash script does not work, when I execute it as
./lamescript "/mnt/hde1/windows/desktop/from other hd/to encode.wav"
Code:

#!/bin/bash


#runs the --preset standard lame, outputs to input.mp3

lame --preset standard \"$1\"

echo "Finished executing Lame encoder..."

exit

...it gives an error because it interprets all the text after a space as another command line argument.
What confuses me though, is that if I echo the same command, everything looks to be formated exactly as it is when I type it directly into the shell, which works.

Any ideas??

~Andrew

Demonbane 06-13-2004 08:08 PM

change \"$1\" to just $1
and if the path contains spaces try using a backslash before the space, instead of double quotes
eg.
/mnt/hde1/windows/desktop/from\ other\ hd/to\ encode.wav

azwr 06-13-2004 11:15 PM

Thanks for the quick response, but so far neither worked. If it makes any difference, I have a similar problem with the wine in my KDE menu ... it has the command "wine %f" and if the filename or directory has spaces in it, it won't work using the "open with..." from knqueror, but it works fine directly in the bash shell.

azwr 06-18-2004 06:57 PM

Well, just thought I'd update my own thread in case anyone else has any similar problems ... I believe I've narrowed it down to being an error in the way this build of Lame parses the command-line arguments (although I'm still confused as to why it would work from a shell but not from a script).
I say this because I've made some scripts to execute other programs with arguments with spaces in the path, and it works just fine. For example,

Code:

#!/bin/bash

#script to execute foobar2000 in wine...

wine "/mnt/hde1/Program Files/foobar2000 0.8/foobar2000.exe"

exit

works with no problems.

Guess I'll let this one go until I run across some good reason why one works and not the other,

~Andrew


All times are GMT -5. The time now is 03:36 PM.