Saturday, April 20, 2024
7
rated 0 times [  7] [ 0]  / answers: 1 / hits: 13229  / 2 Years ago, mon, may 23, 2022, 5:00:34

Working on some bash functions, I didn't know source ... command, so I used eval $(cat ...) instead. Now I am wondering, whethe should I change every use of that, or is it just the same function?



They appear to work the same now, but maybe there will be some misleading differences later, I just want to know.


More From » command-line

 Answers
0

eval $(cat ...) doesn't work in all cases. For example line breaks are converted to a single space by $(cat ...) before the content is processed by eval. This often breaks multi line statements like loops and here documents.



Try for example the following file with both methods:



for i in 1 2 3; do
echo $i
done

cat<<EOF
a
b
c
EOF

[#36227] Wednesday, May 25, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
itteast

Total Points: 291
Total Questions: 123
Total Answers: 104

Location: Tuvalu
Member since Wed, Mar 29, 2023
1 Year ago
;