How can I pass variables to a file printed from outside a bash script?
5
votes
1
answer
328
views
Assuming I have a variable
v="c d e f g"
and a file with the content:
line1
$v
line3
How can I make a bash script print this file with the content of the variable in line 2 as if I was using a here-document like this:
#!/bin/bash
v="c d e f g"
cat << EOF
line1
$v
line3
EOF
Output:
line1
c d e f g
line3
Asked by nath
(6094 rep)
Mar 29, 2024, 09:11 AM
Last activity: Mar 29, 2024, 02:18 PM
Last activity: Mar 29, 2024, 02:18 PM