ProgrammingThis 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.
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.
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:
The odd thing about this is that echo, when run from the script, acts as though its been executed with the -e command-line option, meaning that when given the command
Code:
"C:\Program Files\Interplay\Fallout\falloutw.exe"
it interprets the \f as a carriage return and turns it into
Code:
"C:\Program Files\Interplay\Fallout
alloutw.exe"
Stranger still, when I try it in a bash shell it executes as it should.
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!
Last edited by insecurityman; 09-13-2007 at 09:04 PM.
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629
Rep:
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...
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:
Use printf rather than echo for both reliability and portability:
Code:
printf "%s\n" "$*\n" | grep ...
Quote:
The odd thing about this is that echo, when run from the script, acts as though its been executed with the -e command-line option, meaning that when given the command
Code:
"C:\Program Files\Interplay\Fallout\falloutw.exe"
it interprets the \f as a carriage return and turns it into
Code:
"C:\Program Files\Interplay\Fallout
alloutw.exe"
Dash adheres pretty closely to the POSIX/XSI standard, which says that echo shall interpret certain escape sequences rather than render them literally.
Quote:
Stranger still, when I try it in a bash shell it executes as it should.
Bash has a number of non-POSIX extensions.
Quote:
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?
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.
This is from ages ago, but it's a good question and it's not solved here.
Quote:
Originally Posted by insecurityman
Stranger still, when I try it in a bash shell it executes as it should.
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!
This is common. Especially for something like 'echo'.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.