Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8621

Other programming languages • bash syntax problem with heredoc

$
0
0
Hi

I have a script that generates another script (to be run later as root). I used the heredoc solution

Code:

cat << EOF > google-sync.sh#! /bin/bash# checking root...# file to editCHROME_PREFS_FILE="/etc/chromium.d/default-flags"echo "# Google Sync" >> "\$CHROME_PREFS_FILE"echo "export CHROMIUM_FLAGS=\"$CHROMIUM_FLAGS --oauth2-client-id ... "" >> "\$CHROME_PREFS_FILE"EOF
However, although I tried many things, $CHROMIUM_FLAGS is always interpreted as an empty env variable. I just want it to be written as is.
I tried to escape the $ with \$ or by despair other stupid things like \\ or adding (), {}, '' and so on... Nothing worked.

I fixed the issue with another line of code and like this

Code:

echo "export CHROMIUM_FLAGS=\"@CHROMIUM_FLAGS --oauth2-client-id= ... "" >> "\$CHROME_PREFS_FILE"# replace @ by $ so \$CHROMIUM_FLAGS is written correctlysed -i 's/@CHROMIUM/\$CHROMIUM/g' "\$CHROME_PREFS_FILE"
So I could fix it and make it work but I'd love to understand and learn how to do it. There must be a way but I couldn't find it on my own.

Thanks in advance
Guillaume

Statistics: Posted by dwam — Mon Sep 08, 2025 8:24 am



Viewing all articles
Browse latest Browse all 8621

Trending Articles