Add 2 lines only one time into a file but not form next time in shell script

82 views Asked by At

Can any one help me to add 2 lines into a file when bash shell script is executed. when we run the same script next time, it should not add same lines into the file from next time onwards.

1

There are 1 answers

0
user3004356 On

To add lines in a file you can use echo statements in your shell script. In your shell script you need to check whether the file exists or not first or create one.

TRANSLOG=/tmp/translog.txt
 if [ -e $TRANSLOG ]; then
          echo "File translog already exists!"
        else
          echo >> $TRANSLOG
        fi  
echo -e "line1" > $TRANSLOG;
echo -e "line2" > $TRANSLOG;