Quantcast
Channel: User Brian - Server Fault
Viewing all articles
Browse latest Browse all 41

Answer by Brian for recognize bash variable inside a text file

$
0
0

One option is to use sed to edit the files. This lets you limit what variables get filled in.

This will fill in template.txt and output it to filled.txt:

sed -e "s/\$HOSTNAME/$HOSTNAME/" -e "s/\$USER/$USER/" template.txt > filled.txt

template.txt:

server name: $HOSTNAMEcurrent user: $USER

filled.txt:

server name: ubuntu-servercurrent user: leafar

Viewing all articles
Browse latest Browse all 41

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>