LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 02-22-2003, 03:35 PM   #1
afshin
LQ Newbie
 
Registered: Jan 2003
Location: Los Angeles
Distribution: SuSE 8.2
Posts: 26

Rep: Reputation: 15
Question Quotes in command line expression


Hello,

I'm having a problem with executing a shell command whose argument is a filename which may have single quotes, double quotes, or white spaces. Spcecifically, I need to execute the following command from a PHP script:

Code:
xmms-shell -e "load 'filepath'"
The problem is that if filepath contains a single or double quote, then the shell interpreter thinks its the end of the argument. Is there a way to escape the quotes to avoid this problem?

Thanks.

Afshin
 
Old 02-22-2003, 05:35 PM   #2
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
The usual escape character for shells is the backslash '\'. It's like the escape-character standard in Unix

xmms-shell -e "load \'filepath\'"
 
Old 02-24-2003, 12:23 AM   #3
afshin
LQ Newbie
 
Registered: Jan 2003
Location: Los Angeles
Distribution: SuSE 8.2
Posts: 26

Original Poster
Rep: Reputation: 15
I tried that, but it seems that it's being interpreted as a line break. The following is the output:

Incomplete command. Multi-line entry of commands not yet implemented.

Any other suggestons??

Thanks.
 
Old 02-24-2003, 01:42 AM   #4
fsbooks
Member
 
Registered: Jan 2002
Location: Missoula. Montana, USA
Distribution: Slackware (various)
Posts: 464

Rep: Reputation: 52
This works for bash, probably php as well.

set a variable, and use the variable in the script as such:

xmms-shell -e load "$filepath"

You may need, you might say a back door to get the variable set, since if you want to set, say hello to be .. hello " how are you that will not work. Try the following and see if it works and can be adapted to your needs.

$ cat > testlist
hello how are you
hello " how are you
hello ' how are you
<cntl-D>
$cat testfile|while read invar
> do
> test="$invar"
> echo test is --- "$invar"
> done
test is --- hello how are you
test is --- hello " how are you
test is --- hello ' how are you
$

This allows embedding single quotes, double quotes, and spaces. Most of these I of course avoid, except in all of the .ogg music I record (I gather you are in the same boat). It is just easier to write my scripts to fit the default names and keep my .cddb directory consistent with the network database than to rewrite everything. I do have a little problem with slashes "/" in filenames (Celtic medleys tend to like those), and I also just found a song I had "lost" that was called "...and Every Year Thereafter" (...those leading periods you know :-)
 
Old 02-24-2003, 08:27 AM   #5
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Oh! Silly me.

xmms-shell is the one interpreting that expression. (I just looked at the output of xmms-shell -help, and it looks like -e tells it "evaluate this expression). So it is not bash that you need to worry about, it's xmms-shell. Apparently xmms-shell interprets the backslash as the line-continuation character (which it is, in bash too I think, but only if it's followed by a linefeed).

I do not seem to have xmms-shell installed, so maybe you should check out its manpages to see if there's some special format to use for the expression after -e
 
  


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
Problems with quotes and double quotes Andruha Slackware 6 01-02-2010 05:44 PM
Using single quotes vs double quotes in PHP strings vharishankar Programming 6 07-11-2005 12:41 PM
Command to output file content line by line aznluvsmc Programming 2 09-12-2004 08:45 PM
51 characters only in the 1st Line of command line eggCover Linux - General 2 07-29-2004 02:28 PM
same find command not working in bash script, quotes? QuakerOatz Linux - Software 1 07-14-2003 01:04 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:50 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