Reputation: 1289
cat test.sh
#! /usr/bin/env bash
#some other commands
#some other commands
loc="$(which chromium-browser)"
cat > loc.txt <<'endmsg'
location = '$loc'
endmsg
I have simplied my script to properly explain my issue. I am trying to save the output of a variable in another file using heredoc .But it seems that heredoc simply saves the raw text present inside endmsg tags
Currently
cat loc.txt
location = '$loc'
Since "which chromium-browser" is actually - /usr/bin/chromium-browser
Expectation
cat loc.txt
location = /usr/bin/chromium-browser
is there any way by which i could save the actual variable output in another file and not literally save the raw text. Its fine its the answer doesn't uses heredoc for achieving this , although preferably it shouldn't be complex for doing something so simple.
Upvotes: 1
Views: 201
Reputation: 2774
Simply remove the single quotes:
#! /usr/bin/env bash
#some other commands
#some other commands
loc="$(which chromium-browser)"
cat > loc.txt << endmsg
location = $loc
endmsg
will work fine.
Upvotes: 1