Search This Blog

Monday, October 2, 2023

Shell script 20

Question: Get the files from different directories by using case  statement

Answer:

#!/usr/bin/bash

if [ $# -eq 0 ]

then

        echo "Usage: $0 <case_number>"

        exit 1

fi

case_number="$1"

case "$case_number" in

        1)

                dir="/home/kalam/pnr_inputs/"

                files=("top.spef" "top.vi") ;;

        2)

                dir="/home/kalam/synth_inputs/"

                files="leaf_inst.rpt" ;;

        *)

                echo "Invalid case_number, Please choose 1 or 2"

                exit 1 ;;

esac

if [ ! -d "$dir" ]

then

        echo "Directory $dir does not exist"

        exit 1

else

        for file in "${files[@]}"

        do

        file_path="${dir}${file}"

        if [ -f "$file_path" ]

        then

                echo "$file_path"

        else

                        echo "File $file_path not found"

        fi

done

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...