Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

line 54: warning: here-document at line 42 delimited by end-of-file (wanted `EOF') [duplicate]

Tags:

bash

eof

I got bash script, but when I run it I got some error:

line 54: warning: here-document at line 42 delimited by end-of-file (wanted `EOF')

#!/bin/bash
echo "PODAJ IMIE"
read imie
echo  "PODAJ NAZWISKO"
read nazwisko

alias="$imie$nazwisko"
echo "$alias"


while [ 1 ]
do

        i=1

        if [ `egrep $alias /etc/passwd |wc -l` -gt 0 ]; then i=0
        fi

        if [ $i -eq 0  ]; then
                echo "Uzytkownik o podanym aliasie już istnieje!"
                echo "PODAJ INNY ALIAS np. "$alias"1"
                read alias

        else
                echo "PODAJ HASLO"
                read -s password
                echo "PODAJ NUMER POKOJU"
                read pokoj

                #adduser --disabled-password --gecos "$imie $nazwisko,$pokoj, ," $alias
                adduser --quiet --disabled-password -shell /bin/bash --home /home/$alias --gecos "$imie $nazwisko, $pokoj, , " $alias
                echo "$alias:$password" | chpasswd
                #echo -e "$haslo\n$haslo\n" | sudo passwd $alias


                dir=/home/$alias
                mkdir $dir/public_html
                mkdir $dir/samba
                cd $dir/public_html
                mkdir private_html

                cat <<EOF >>$dir/.bashrc

                echo "alias ps =/bin/ps"
                echo "alias ls =/bin/ls"
                t=\`date +%F.%H:%M:%S\`
                echo "WITAJ\n"
                echo "DZISIAJ MAMY:\$t"
                echo "TWOJE OSTATNIE LOGOWANIE:" && " lastlog -u \$USER | tail -n 1 | awk '{print       \$4" "\$5" "\$6" "\$7" "\$9}'"
                EOF

                break
        fi
done
like image 778
Budrys Avatar asked Nov 29 '14 09:11

Budrys


2 Answers

The EOF needs to be at the start of a line, and with nothing after (including no whitespace).

Some of the echos in that block are suspicions. The text up to the end marker will be copied into the file as-is after variable substitution, not executed - and it doesn't look like you want substitution here.

Try this: (notice the quotes around "EOF" on the cat line)

            cat <<"EOF" >>$dir/.bashrc
alias ps=/bin/ps
alias ls=/bin/ls
t=$(date +%F.%H:%M:%S)
echo "WITAJ\n"
echo "DZISIAJ MAMY: $t"
echo "TWOJE OSTATNIE LOGOWANIE:" $(lastlog -u $USER | tail -n 1 | awk '{print       $4" "$5" "$6" "$7" "$9}')
EOF
like image 85
Mat Avatar answered Sep 30 '22 22:09

Mat


The EOF delimiter needs to be aligned in the leftmost column.

Here's what I often do for alignment.

Lots
    Of
        Indents
            cat <<-____________HERE
                boo
____________HERE
        done
    done
done
like image 23
tripleee Avatar answered Sep 30 '22 21:09

tripleee