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 -z is given as an argument to the script.
Here’s the relevant part:
zipped='' zipcommand='>' if [ '$1' = '-z' ] then zipped='zipped ' filename='${filename}.zip' zipcommand='| zip >' fi echo 'Creating ${zipped}patch file $filename...' svn diff $zipcommand $filename
This doesn’t work because it passes the | or > contained in $zipcommand as an argument to svn.
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.
Thanks!
I would do something like this (use bash -c or eval):
This appears to work, but my version of zip (Mac OS X) required that i change the line:
to
Edit: incorporated @DanielBungert’s suggestion to use eval