Reputation: 29658
The actual situation is a bit complicated, but the issue I'm running into is that I have an echo command within an eval command. Like so:
$ eval echo 'keep my spacing'
keep my spacing
$ echo 'keep my spacing'
keep my spacing
I was wondering how I could keep eval from stripping my spacing so that the first command prints out the same message as the second...
Here's a closer example to what's actually going on:
$ eval `python -c 'print "echo \"keep my spacing\""'`
keep my spacing
Upvotes: 1
Views: 3629
Reputation: 204698
$ . <(python -c 'print "echo \"keep my spacing\""') keep my spacing
Upvotes: 0
Reputation: 125768
The problem (in the python example) is that the command substitution (the backquoted expression) isn't protected by quotes. To fix, put double-quotes around it (and to make the quotes nest better, use $()
instead of backquotes):
eval "$(python -c 'print "echo \"keep my spacing\""')"
Upvotes: 1
Reputation: 39733
It's not the fault of eval
:
`python -c 'print "echo \"keep my spacing\""'`
prints
"keep my spacing"
Instead you could do this:
python -c 'print "echo \"keep my spacing\""' | bash
This prints
keep my spacing
Upvotes: 1
Reputation: 181745
eval "echo 'keep my spacing'"
keep my spacing
If that does not work for you, please explain more about the actual situation.
Upvotes: 1