LinuxQuestions.org
Visit Jeremy's Blog.
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 06-13-2004, 07:29 PM   #1
azwr
LQ Newbie
 
Registered: Jun 2004
Distribution: Gentoo, Knoppix HD Install (Debian)
Posts: 7

Rep: Reputation: 0
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
 
Old 06-13-2004, 08:08 PM   #2
Demonbane
LQ Guru
 
Registered: Aug 2003
Location: Sydney, Australia
Distribution: Gentoo
Posts: 1,796

Rep: Reputation: 47
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
 
Old 06-13-2004, 11:15 PM   #3
azwr
LQ Newbie
 
Registered: Jun 2004
Distribution: Gentoo, Knoppix HD Install (Debian)
Posts: 7

Original Poster
Rep: Reputation: 0
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.
 
Old 06-18-2004, 06:57 PM   #4
azwr
LQ Newbie
 
Registered: Jun 2004
Distribution: Gentoo, Knoppix HD Install (Debian)
Posts: 7

Original Poster
Rep: Reputation: 0
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
 
  


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
Bash script to remove capitalisation and spaces form a filename scuzzman Programming 11 05-18-2008 12:28 PM
bash script with spaces Quantum0726 Programming 2 11-14-2005 09:26 PM
Passing parameters to bash script Kamikazee Programming 4 10-01-2005 06:41 AM
Spaces in bash parameters rose_bud4201 Programming 5 03-11-2005 06:57 AM
Passing Parameters to Bash Script mooreted Linux - Software 3 04-05-2004 09:08 PM

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

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

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