[NCLUG] Oops,
Bob Proulx
bob at proulx.com
Fri Feb 21 08:54:37 MST 2014
> alan schmitz wrote:
> > Is it possible to see anything useful by adding
> > set -x
> > to the beginning of the script and check the output?
The -x option will cause the shell to print trace statements as it
executes shell commands. This is very useful when debugging. You can
see where the script is going and what commands and arguments are
being run. In the presented script however there is only one
command. Even without -x we already know what is happening.
Luke Jones wrote:
> For serious shall scripting, you probably need 'trap (1)' as well.
One of the utilities of trap handlers becomes necessary if there are
temporary files. Then those temporary files can be cleaned up when
the script is interrupted. In the presented script there aren't any
temporary files in use. So nothing to do in a trap handler.
I debated with myself the utility of adding the script error messages.
After all 'tar' itself will produce an error message if there is a
reason to do so. And therefore I think for this small snippet I would
make it smaller by letting tar's exit code be the one seen by the
caller. Something that can be done in this very special case of there
really only being one command. Simpler is simpler.
#!/bin/sh
cd /home || exit 1
tar cvzf /mnt/UserBackup/BKkerrym2.tar.gz \
--one-file-system \
--exclude=kerrym2/KerrysStuff \
--exclude=kerrym2/Pictures \
--exclude=kerrym2/Downloads \
--exclude=kerrym2/.wine/drive_c \
kerrym2
# Let the exit value of tar "fall through" the bottom of the script.
# The shell exits with the exit status of the last command.
Bob
More information about the NCLUG
mailing list