Skip to content
Advertisement

Save File With Shell Script Content

$net_script is variable and stored text (script content). I need to create run.sh with $net_script content.

$net_script:

echo "Start..."
cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-$1
DEVICE=$1
TYPE=Ethernet
IPADDR=$2
NETMASK=255.255.255.0
GATEWAY=$3
ONBOOT=yes
BOOTPROTO=static
PROXY_METHOD=none
BROWSER_ONLY=no
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
EOF

But it’s not stored correctly. I tried echo but that didn’t work.

cat <<'EOF' >> run.sh $net_script EOF

Advertisement

Answer

Try this

echo "${net_script}" > run.sh
Advertisement