Saturday, June 03, 2006

script stdout | shell

when writing a shell script, it is important to make sure it does the correct things, especially when it come to execute the specific commands like rm etcetera. it is advisable to print out to stdout what the commands in the scripts do to make sure no typo/error made.
#! /bin/ksh
for file in *.log
echo rm $file

so when you run the script:
$ ./
rm 1.log
rm 2.log
rm 3.log

it will not execute the rm command since we only use echo. in order to execute it, no need to delete the echo but simpy pipe ( | ) it to the shell:
$ ./ | sh

will delete those 3 log files.

No comments: