<br><br><div class="gmail_quote">On Tue, Feb 26, 2008 at 10:11 AM, Benjamin Smith <<a href="mailto:lists@benjamindsmith.com">lists@benjamindsmith.com</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
In bash, given a string assignment as follows, how do I "add slashes"<br>
automagically, so that it can be safely passed to another program? Notice<br>
that the assignment contains spaces, single-quotes and double-quotes, maybe<br>
god-only-knows-what-else. It's untrusted data.<br>
<br>
Yet I need to pass it all *safely*.<br>
<br>
The appropriate function in PHP is addslashes(); but what is the bash<br>
equivalent? EG:<br>
</blockquote><div><br><br>short answer:  single quotes will handle all characters, except single quotes.<br><br>long answer:  man bash<br> the section called QUOTING may help you figure a solution.<br><br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<br>
#! /bin/sh<br>
A="This isn't a \"parameter\"";</blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
B=`/path/to/somecommand.sh $A`;<br>
exit 0;<br>
<br>
<br>
Thanks,<br>
<br>
-Ben<br></blockquote></div><br>HTH,<br>-Bob<br>