<p>I have a bash script that creates a Subversion patch file for the current directory. I want to modify it to zip the produced file, if <code>-z</code> is given as an argument to the script.</p>

<p>Here's the relevant part:</p>

<pre><code>zipped=''
zipcommand='&gt;'

if [ "$1" = "-z" ]
then
   zipped='zipped '
   filename="${filename}.zip"
   zipcommand='| zip &gt;'
fi

echo "Creating ${zipped}patch file $filename..."

svn diff $zipcommand $filename
</code></pre>

<p>This doesn't work because it passes the <code>|</code> or <code>></code> contained in <code>$zipcommand</code> as an argument to <code>svn</code>.</p>

<p>I can easily work around this, but the question is whether it's ever possible to use these kinds of operators when they're contained in variables.</p>

<p>Thanks!</p>

I would do something like this (use bash -c or eval):
```
```
zipped=''
zipcommand='>'

if [ "$1" = "-z" ]
then
   zipped='zipped '
   filename="${filename}.zip"
   zipcommand='| zip -@'
fi

echo "Creating ${zipped}patch file $filename..."

eval "svn diff $zipcommand $filename"
# this also works: 
# bash -c "svn diff $zipcommand $filename"
```
```
This appears to work, but my version of zip (Mac OS X) required that i change the line:
```
```
zipcommand='| zip -@'
```
```
to
```
```
zipcommand='| zip - - >'
```
```
Edit: incorporated @DanielBungert's suggestion to use eval