Free web development scripts for the webmasterDevelopment Scripts

 Site Navigation
 o Development Scripts
 o Text Only Edition
 o PHP.net News
 o Tutorials
 o Register an account
 o New entries this week
 o Affiliates/Links
 o Contact Us
 o About us
 o Advanced Search

 Browse Path
 o 3 users online
 o Most users online: 67
 o Home
  o Shell
   o Files
    o Script

 Member Login
User Name
Password

 Standards
Valid XHTML 1.0!
Valid 
CSS!

 Recommended Links
 o PHP Freaks
 o Designer Baby Clothes
 o Advertise Here Make Money
 o Wedding Vendor Directory
 o devnet
 o OxyScripts
 o Free Wedding Websites
 o designplace
 o Open Source Design

Overwrite a file with another. (Rated 0)

Description:

Overwrite one file with another. From "The Unix Programming Environment".

Code starts here


#!/bin/sh
#overwrite: overwrite file with output of command
#note: must use redirection of input from file in command if required

opath=$PATH
PATH=/bin:/usr/bin:/usr/local/bin

case $# in
0|1) echo 'Usage: overwrite file cmd [args]' 1>&2; exit 2
esac

file=$1; shift
new=/tmp/overwr1.$$; old=/tmp/overwr2.$$
trap 'rm -f $new $old; exit 1' 1 2 15

export PATH=$opath;
if "$@" > $new
then
cp $file $old
trap '' 1 2 15
cp $new $file
else
echo "overwrite: $1 failed, $file unchanged" 1>&2
rm -f $new $old
exit 1
fi
rm -f $new $old


Submitted by Devscripts on 27-02-2003 20:35


Rate This Script

User Contributed Comments

Registered Members login
© Copyright 2003 - Devscripts.net