Solved cannot pass variable inside here document

Hello,

Could someone please help me understand why the "hostname" (in bold) variable is not been passed to my << 'EOF' > file?
Code:
#!/bin/sh
#

hostname=$(hostname -f)

cat << 'EOF' > /etc/rc.conf
hostname="$hostname"

cron_flags=" -J 15"

# Disable Sendmail by default
sendmail_enable="NONE"
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"

# Run secure syslog
syslogd_flags="-c -ss"

# Enable IPv6
#ipv6_activate_all_interfaces="YES"

### Web Configuration
hiawatha_enable="YES"
php_fpm_enable="YES"

### Enable ssmpt at boot
ssmtp_enable="YES"
EOF
Thank you
 
By putting your end mark in single quotes, you make the heredoc behave like a single-quoted string, so no variable expansion happens inside. Just write cat << EOF > /etc/rc.conf instead.
 
Back
Top