![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Come and work for me! (UK) | TonyChapman | Linux | 2 | 03-25-2008 01:08 AM |
| How does it work? | nat123 | Linux | 1 | 11-04-2007 09:13 PM |
| Script doesn't work, but commands inside work | cheongww | UNIX for Dummies Questions & Answers | 2 | 11-14-2006 06:52 PM |
| sed doesn't work | billy5 | Shell Programming and Scripting | 3 | 08-26-2005 12:44 AM |
| How does tee work | Foxgard | UNIX for Dummies Questions & Answers | 1 | 06-18-2005 12:58 PM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Will this work?
I'm trying to check if files already exist in a directory. They have the same basename (exsyctr1), but 4 different extensions. If the files exist, then I make backups of them, then copy them from another directory ($livecomp/data) to the current one ($copycomp/data). If they don't exist, just perform the copy.
Will the script below work? Code:
if [ -f $copycomp/data/exsyctr1.* ] then echo "Changing to $copycomp/data/" cd $copycomp/data echo "Backing up existing files" cp exsyctl1.* *.bak echo "Copying from $livecomp/data/ to $copycomp/data/" cp $livecomp/data/exsyctr1.* . else echo "Copying from $livecomp/data/ to $copycomp/data/" cp $livecomp/data/exsyctr1.* . fi |
| Forum Sponsor | ||
|
|
|
||||
|
I would use a loop like the following, but it's just one possible way I suppose...
Code:
echo "Changing to $copycomp/data/"
cd $copycomp/data
for FILE in `ls $copycomp/data/exsyctr1.*`
do
if [ -f $FILE ]; then
echo "Backing up existing files"
cp $FILE ${FILE%.*}.bak
fi
done
echo "Copying from $livecomp/data/ to $copycomp/data/"
cp $livecomp/data/exsyctr1.* .
If you're serious about finding out different ways to do things, read this post. Maybe you'll like one way more than another. |