1

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.

Sachin
  • 1,067
  • 1
  • 6
  • 23

1 Answers1

1

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.

seumasmac
  • 1,824
  • 15
  • 7