Parenthesis and other odd characters passed to bash function
I would like to code a function which will accept a '(' in the parameter, and do some stream editing in the process. So for example:
------------------------------------------------------------------------ #!/bin/bash function foo () { # use the entire commandline ($@) as a single argument ## this allows spaces output=`echo "$@" | sed 's|(|\\\(|g'` echo $output } foo Hello (world) ----------------------------------------------------------------------- If I do this, bash will complain about the '(' and ')' output: ./foobar.sh: line 11: syntax error near unexpected token `(' ./foobar.sh: line 11: `foo Hello (world)' There are other characters, such as '*', which cause problems. The way around this is to use double quotes in the call: foo "Hello (world)" output: Hello \(world) So my question is: How can I re-write foo() to avoid using the double quotes when I make the call? Thanks in advance Jake |
Quote:
|
Thanks for the reply.
|
All times are GMT -5. The time now is 06:00 AM. |