Home > Net >  How to read a txt file using echo command in bash
How to read a txt file using echo command in bash

Time:06-07

here is a part of my script. I would like to display the contents of the file repo.txt in the echo command before performing any option. Can somebody please help me to find what option goes in echo line to display the file contents ?

file="repo.txt"
    echo "Do you really want to delete the repos: $file "
    read options
    echo "Option Selected Is $options"
    if [ $options == "yes" ]
    then

CodePudding user response:

Swap:

echo "Do you really want to delete the repos: $file "

for

echo "Do you really want to delete the repos: $(cat $file)"

CodePudding user response:

readarray -t repos < repo.txt
echo "Do you really want to delete the repos:"
printf " - %s\n" "${repos[@]}"
read -p "Answer [y/n]: " ANSWER
if [ "$ANSWER" = "yes" -o "$ANSWER" = "y" ];then
   echo remove
else
   echo skipp
fi


$ ./script.sh
Do you really want to delete the repos:
 - repo1
 - repo2
 - repo3
 - repo4
 - repo5
 - repo6
Answer [y/n]: y
remove
  • Related