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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
02-22-2003, 02:35 PM
|
#1
|
|
LQ Newbie
Registered: Jan 2003
Location: Los Angeles
Distribution: SuSE 8.2
Posts: 26
Rep:
|
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
|
|
|
|
02-22-2003, 04:35 PM
|
#2
|
|
Guru
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018
Rep:
|
The usual escape character for shells is the backslash '\'. It's like the escape-character standard in Unix
xmms-shell -e "load \'filepath\'"
|
|
|
|
02-23-2003, 11:23 PM
|
#3
|
|
LQ Newbie
Registered: Jan 2003
Location: Los Angeles
Distribution: SuSE 8.2
Posts: 26
Original Poster
Rep:
|
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.
|
|
|
|
02-24-2003, 12:42 AM
|
#4
|
|
Member
Registered: Jan 2002
Location: Missoula. Montana, USA
Distribution: fedora, slackware, suse
Posts: 447
Rep:
|
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 :-)
|
|
|
|
02-24-2003, 07:27 AM
|
#5
|
|
Guru
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018
Rep:
|
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
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 09:07 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|