Bash functions return "command not found"

I tried to make this function work without returning errors, but so far I can’t understand what the problem is. I use $ (report_home_space) to insert the contents of functions on a small bit of hmtl, but keep getting the error: report_home_space: command not found on line 30.

 report_home_space () {
          cat <<- _EOF_
                  <H2>Home Space Utilization</H2>
                  <PRE>$(du -sh /home/*)</PRE>
                  _EOF_
  }

I'm new to shell scripts, but I can't find anything wrong with the function syntax, and the spelling seems to be correct. Thanks in advance.

Full script:

#!/bin/bash

# Program to output a system information page

TITLE="System Information Report For $HOSTNAME"
CURRENT_TIME=$(date +"%x %r %z")
TIMESTAMP="Generated $CURRENT_TIME, by $USER"

report_uptime () {
        cat <<- _EOF_
                <H2>system Uptime</H2>
                <PRE>$(uptime)</PRE>
                _EOF_
}

report_disk_space () {
        cat <<- _EOF_
                <H2>Disk Space Ulitilizatoin</H2>
                <PRE>$(df -h)</PRE>
                _EOF_
}

report_home_space () {
        cat <<- _EOF_
                <H2>Home Space Utilization</H2>
                <PRE>$(du -sh /home/*)</PRE>
                _EOF_
}

cat << _EOF_
<HTML>
        <HEAD>
                <TITLE>$TITLE</TITLE>
        <BODY>
                <H1>$TITLE</H1>
                <P>$TIMESTAMP</P>
                $(report_uptime)
                $(report_disk_space)
                $(report_home_space)
        </BODY>
<HTML>
_EOF_
+4
source share
1 answer

By the way, your script is working fine. Did you happen to specify this on a Windows environment before booting into UNIX env? Try to run:

dos2unix script.sh

- Windows unix. .. \r (CR) , \r\n (CR + LF) \n (LF).

, HTML "<HEAD> " .

enter image description here

+4

All Articles