Writing or Appending data into a file

#! /bin/bash
read -p "Enter the file name : " fileName
if [ -f $fileName ]
then
    echo $fileName exist
    if [ -w $fileName ]
    then
        echo Writer permission for $fileName exist.
        echo Starting to write data into $fileName
        echo Press Ctrl+d to save the data to file
        cat >> $fileName  # note >> for append > to override
    fi
fi

Leave a Comment