PiotrO
PiotrO

Reputation: 11

issue with creating file containing $ from bash script

I want produce udev rule file from bash script. For this I'm using cat command. Unfortunately produced file has missing "$" char. Here is example test.sh script:

#!/bin/sh


rc=`cat <<stmt1 > ./test.txt

-p $tempnode
archive/$env{ID_FS_LABEL_ENC}

stmt1`

Result is following:

cat test.txt 

-p ''
archive/{ID_FS_LABEL_ENC}

Where issue is ?

Upvotes: 1

Views: 61

Answers (1)

Mat
Mat

Reputation: 206709

If you don't want any variable interpolation, use:

#!/bin/sh

group="test_1"

cat <<'stmt1' > ./test.txt

-p $tempnode
archive/$env{ID_FS_LABEL_ENC}

stmt1
rc=$?

(Notice the '' around stmt1.)

Upvotes: 5

Related Questions