I have a text file which is usually filled with multiple lines which I want to "print" with a while loop. The text inside this file contains variables - my problem is, that these variables are not interpreted unlike a similar test-string containing variables stored inside the script. Is it possible to also interpret those variables from my external file or do I have to parse them beforehands etc.? What is the difference between $LINE_INSIDE
and $LINE_OUTSIDE
?
I tried some suggestions from other questions like ${!varialbe_name}
and different constructs with quote signs but with no luck so far.
#!/bin/bash
# color.sh
BLUE='\033[1;34m'
NC='\033[0m' # No Color
LINE_INSIDE="${BLUE}Blue Text${NC}"
echo -e ${LINE_INSIDE}
while read LINE_OUTSIDE; do
echo -e ${LINE_OUTSIDE}
done < text_file
Output:
Additional Information: I (indeed) also have shell-commands in my input-text-file which should not by executed. Only the variables should be expaned.
eval "echo -e ${LINE_OUTSIDE}"
– Arkadiusz Drabczyk May 26 '19 at 17:59LINE_INSIDE='${BLUE}Blue Text${NC}'
(single quotes). – muru May 26 '19 at 18:03Löschen mit Fortschrittsanzeige sudo rm -rv ${BLUE}/pfad${NC} | pv -l -s $(sudo find ${BLUE}/pfad${NC} | pv -l | wc -l) > /dev/null` I should have mentioned it at the first place, so maybe I open a followup question regarding that.
– n-tchen Jun 01 '19 at 07:46