General TC > Programming & Scripting - Unofficial

[Solved] variable expansion inside a here-file issue

(1/5) > >>

aus9:
Hi

most tiimes, a script that cats a line of text into a /pathway2/file works for me.

I am close on this one
all the lines in a terminal look like
> line1
> line 2 etc
my script is also pasting a tce.install script so I use EOF and that looks good as
> EOF

Up the top I change the demiliter to ZZZ and the rest of the lines look good until the last line
which reads as

> ZZZ
but that is supposed to be end of the file.

I have used ctrl + c to close down attempted input

Any clues ?
here is my top middle and bottom lines
( I have checked with echo that the variables are good)

cat > $P/usr/local/share/$P/files/$GET <<ZZZ

# tce.install
EOF

ZZZ

thanks for reading

Paul_123:
It’s hard to follow script posts with very fragmented lines of code.  Post the full script or a bigger portion of the code.

patrikg:
Have you tried to add it with double quotes like this example.


--- Code: (bash) ---cat > /etc/resolv.conf << "EOF"
nameserver 8.8.8.8
nameserver 8.8.4.4
EOF

--- End code ---

jazzbiker:
I don't know whether I've understood the problem correctly but for me:

--- Code: ---tc@box:~$ cat > bbb <<ZZZ
> cat > ccc <<EOF
> ls
> EOF
> ZZZ
tc@box:~$ cat bbb
cat > ccc <<EOF
ls
EOF
tc@box:~$ . ./bbb
tc@box:~$ cat ccc
ls

--- End code ---

looks like nested here-files work.

aus9:
Hi Rich
Please mark as solved.

The solution was a test based on patrikg reply but with a small change away from ZZZ

--- Code: ---cd /tmp && sudo su

cat > test << "EOF2"
#!/bin/sh
# test we are root
if [ "$(id -u)" != "0" ]; then
   echo "run as root now exitting"
   exit 1
fi

P=get-chromium
TCDIR=/etc/sysconfig/tcedir/optional

# tce.install
###########
mkdir -p $P/usr/local/tce.installed
cat > $P/usr/local/tce.installed/$P << 'EOF'
#!/bin/sh
[  -f /var/run/dbus/pid ] || /usr/local/etc/init.d/dbus start
EOF
chown -R root:staff  $P/usr/local/tce.installed
chmod -R 775 $P/usr/local/tce.installed

# now we put into member's tcedir
cd $TCDIR
cp /tmp/$P.tcz*  .

EOF2
--- End code ---
Note that I am reluctant to post full code, as I am simple coder, I need to build the get TCE and then test it. I have a fair chance I need to improve it and do not want for others to point out all my mistakes....before I get a chance to see some for myself.  ;D

Note this is a private TCE built for private purposes so I am allowed to autostart dbus for this target member group. The size of the download and the resultant TCE may scare some members on arm so I suspect very few will want it.

Thanks for reading

Navigation

[0] Message Index

[#] Next page

Go to full version