Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange shell script behavior 1

Status
Not open for further replies.

pwozney

ISP
Apr 18, 1999
5
CA
I'm writing a script to automatically create a backup of my filesystem which I will then burn to a cd. Everything except this works.

BACKUP_NAME="phoenix"
BACKUP_DIR="/$BACKUP_NAME"
CREATE_FS="find . -mount -depth -print0 | cpio -apdmu0 $BACKUP_DIR"
echo "$CREATE_FS"
cd /
$CREATE_FS


Yields this:

find . -mount -depth -print0 | cpio -apdmu0 /phoenix

find: paths must precede expression
Usage: find [path...] [expression]


Very strange I say.

If I run just this: "find . -mount -depth -print0" outside of the script it does what you would expect, flooding my screen with gobs and gobs of filenames.

What do you think? It actually worked fine inside the script...until I moved the command to a variable name. Why is it behaving differently now?
 
Set up xtrace. The only time that I have seen that error related to find is when the command line attempts to parse the command arguments instead of allowing the find command to do what you wish.

Part of the reason why it may be working fine from the command line is you just happened to be in the directory where the files exist so the command line passes the proper information to the find command.

The only way I know to correct this is to double quote the find arguements so the command line does not attempt to parse them.

Hope this helps you.

Steve
 
eval $CREATE_FS

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks vgersh99!

This worked:
eval $CREATE_FS

I did try to trace this script out, but I couldn't figure out how to get strace to show the command line options that were passed to find...anyway it works like a charm now!

Thanks,

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top