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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
02-22-2003, 03: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, 05:35 PM
|
#2
|
LQ 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-24-2003, 12:23 AM
|
#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, 01:42 AM
|
#4
|
Member
Registered: Jan 2002
Location: Missoula. Montana, USA
Distribution: Slackware (various)
Posts: 464
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, 08:27 AM
|
#5
|
LQ 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
|
|
|
All times are GMT -5. The time now is 05:50 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
|
|