简体   繁体   中英

Unix. Shell Script

I have a script it prints out a table for the rest of my project. My project is working fine however. When I use the script it prints out two errors along with the gui interface. I dont have the banner command or sudo (to install) to use those graphic interfaces.

#!/bin/bash


Welcome()
{
echo
"
|--------------------------
|          Red Hat         |
|     Enterprise Linux     |
|                          |
|    Server Release 5.3    |
|     Codename Tikanga     |
----------------------------
"
}

Welcome

However it prints out this

working: line 129:

    |--------------------------
    |          Red Hat         |
    |     Enterprise Linux     |
    |                          |
    |    Server Release 5.3    |
    |     Codename Tikanga     |
    ----------------------------

: command not found

instead of just

|--------------------------
|          Red Hat         |
|     Enterprise Linux     |
|                          |
|    Server Release 5.3    |
|     Codename Tikanga     |
----------------------------

You need to use:

echo '
|--------------------------
|          Red Hat         |
|     Enterprise Linux     |
|                          |
|    Server Release 5.3    |
|     Codename Tikanga     |
----------------------------'

Basically start quote after echo in the same line.

In a shell script, a command ends with the end-of-line. So you have an

echo

which prints an empty line, followed by several lines of gibberish, which the shell tries to interpret as command, which it cannot find. Thus the error message (which is printed by the shell, not your script's echo ).

(Wanted to edit in a solution at this point, but anubhava beat me to it. His solution works because the end-of-line is inside the string started by the ' , so the whole string including newlines is interpreted as part of the echo command.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM