0

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.

user27
  • 1,557
  • 4
  • 16
  • 16

1 Answers1

0

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;
user3004356
  • 870
  • 4
  • 16
  • 49