Search This Blog

Sunday, October 1, 2023

Shell script 12

Question:

Open a file and read the content and print the lines one by one, also check the file is exist or not if it is absent say file is absent  

Answer:

#!/usr/bin/bash

path="/home/kalam/filename.sh"

if [ -e $path ]

then

        echo "File is exists in the following path: $path"

        for line in $(cat "$path")

        do

                echo "line: $line"

        done

else

        echo "file is absent"

        echo "Please provide realpath of the file and re-run the script"

        echo "Thank you for using this script"

        exit 1

fi



No comments:

Post a Comment

What is the sanity checks you have done for STA?

 Sanity checks for STA: Linking Checks: We need to check., is there any missing modules or missing pins in a library. this is done by link c...