Home » Blog » Write a shell script that store content from console to file until end is encountered and print number of line and content of stored file

Write a shell script that store content from console to file until end is encountered and print number of line and content of stored file

echo "Enter Content"
touch contentfile
end="end"
while true
do
	read content
	if [ "$content" != "$end" ]
	then
		echo $content >> contentfile
		line=$((line + 1))
	else
		break
	fi
done
echo "-----------------------------------------"
echo "           Content Of File"
echo "Name Of File :: contentfile"
echo "Number Of Line $line"
read data < contentfile
while read data
do
	echo "$data"
done < contentfile
echo "-----------------------------------------"

 

Leave a Reply

Your email address will not be published.