For all the files (in the current directory) that contain the WORD that is the 1st command line argument, I have to insert the second command line argument on a new line at the head of the file.Then I have to Print usage and exit with status 4 if not given two args. Exit status 1 is there were there are no such files. Exit status 2 if any of the files could not be altered. Exit status 0 otherwise.
For Example:
Suppose the script filename is addwarn.sh then,
echo "I am a string" > f1 echo "I am not a string > f2 ./addwarn.sh "not" '*** WARNING ***' cat f1 f2 I am a string *** WARNING *** I am not a string
What I have tried so far:
#! bin/sh
if [ $? -eq 0 ]; then
exit
fi
if [ $? -ne 0 ]; then
cat *
fi
I am not sure how to make a script, any ideas?
$?in your script?