echo escape character weirdness
I've been working on my first bash script of any complexity - a wrapper script for Wine - and I've been doing okay except for one baffling issue with echo, of all things. The problem comes up in the following command, which I use to strip Wine application command line arguments:
Code:
WINECOMMAND=`echo $@ | grep -o -i ".*\(exe\|bin\|msi\)"` Code:
"C:\Program Files\Interplay\Fallout\falloutw.exe" Code:
"C:\Program Files\Interplay\Fallout This is on Ubuntu Gutsy, and this is a /bin/sh script - is this a dash issue? Would converting the script to /bin/bash clear things up? Or am I just missing something blatantly obvious? (The entire script can be found in this thread, by the way) Thanks for any help! |
Did you try it with backticks <'> or <`>instead of <">?
Btw. #!/bin/sh is used for portability, if you have bash anyhow and use the script only on that machine just change it as you suggested yourself, maybe you'll find the causation later... |
Hi!
Yes, this is a `dash' issue. I tried to run following script Code:
line="C:\Program Files\Interplay\Fallout\falloutw.exe" Code:
$ bash escape.sh You can use something like this: Code:
ECHO='/bin/echo -E' |
Quote:
Quote:
Quote:
Quote:
|
Thanks, all of you - that was really informative. This whole learning bash things is surprisingly fun.
I ended up converting the script over to bash, but the next thing I'll do is convert it back before I start getting too used to bashisms. I'll also start using printf instead of echo - I vaguely remember that issue being brought up in a few C tutorials I did a while back, but I didn't think to apply it here. Thanks once more. |
In case you don't know it already:
http://www.tldp.org/guides.html#abs and for variety's sake http://zsh.sunsite.dk/Guide/zshguide.html |
Unless you need it for portability, I would use egrep instead of grep. I would also enclose the regex in single, rather than double, quotes:
Code:
| egrep -oi '.*(exe|bin|msi)' Code:
| egrep -oi '.*\.(exe|bin|msi)' insecurityman, Is this the right link? http://ubuntuforums.org/showthread.php?t=533257 I can't seem find your script there. Maybe your Ubuntu forum name & the post# would help. |
Call the executable directly.
This is from ages ago, but it's a good question and it's not solved here.
Quote:
You'll find that most shells have an internal version of very simple commands, like ls, echo, pwd, cd, mkdir, etc... I bet you my paycheck* that you can solve this problem by replacing "echo" in your script with "/bin/echo" to call that binary instead of the shell builtin. That will ensure that the 'echo' you call is the one described in the manpage. * disclaimer, I'm currently unemployed. -Arfy |
All times are GMT -5. The time now is 04:12 AM. |