What's wrong with this code?
14 Jun 2003In the grand tradition of ryanr's journal, let's see who figures out what's wrong with this Bourne shell script. First prizeis a Cadillac Eldorado. Second prize is a set of steak knives. Third prize is Cowboy Neal fires you.
Background: yesterday at work, my home-grown backup system choked when it tried to burn a 740MB ISO to CD. (Still waiting for a tape drive.) I decided to finally implement the long-delayed exclusion of certain files (.core, .o, etc.). I know, I know, should've put it in from the start, but this was the first time it became an issue.
Anyhow, I was testing to see if my changes worked, and they didn't: the files were not being excluded. What was doubly weird was that I could run, on its own, the command the script was running, and it would work fine: everything that should have been excluded was. I finally boiled it down to this script:
#!/bin/sh
TAR_EXCLUDE="--exclude='*.core' --exclude='*.a'
--exclude='*.o' --ignore-case --exclude='*cache*'"
# This command works:
/usr/bin/tar cvj --exclude='*.core' --exclude='*.a'
--exclude='*.o' --ignore-case --exclude='*cache*' -f
backup.tar /home/foo
# And this command doesn't:
/usr/bin/tar cvj $TAR_EXCLUDE -f backup.tar /home/foo
I tried putting echo behind each command, and I tried putting -x in the shebang; both showed the same output for both commands. (That make sense?)
What did I do wrong?
Add a comment:
Name and email required; email is not displayed.
Related Posts
QRP weekend 08 Oct 2018
Open Source Cubesat Workshop 2018 03 Oct 2018
mpd crash? try removing files in /var/lib/mpd/ 11 Aug 2018