bash 第 54 行:警告:第 42 行的此处文档由文件尾分隔(需要“EOF”)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27201004/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
line 54: warning: here-document at line 42 delimited by end-of-file (wanted `EOF')
提问by Budrys
I got bash script, but when I run it I got some error:
我有 bash 脚本,但是当我运行它时出现了一些错误:
line 54: warning: here-document at line 42 delimited by end-of-file (wanted `EOF')
第 54 行:警告:第 42 行的此处文档由文件尾分隔(需要“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
回答by Mat
The EOF
needs to be at the start of a line, and with nothing after (including no whitespace).
在EOF
必须在一行的开始,并与后(包括没有空格)什么都没有。
Some of the echo
s 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.
echo
该块中的一些s 是怀疑。在变量替换后,直到结束标记的文本将按原样复制到文件中,而不是执行 - 看起来您不想在这里进行替换。
Try this: (notice the quotes around "EOF"
on the cat
line)
试试这个:(各地注意引号"EOF"
就cat
行)
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 " "" "" "" "}')
EOF
回答by tripleee
The EOF delimiter needs to be aligned in the leftmost column.
EOF 分隔符需要在最左边的列中对齐。
Here's what I often do for alignment.
这是我经常做的对齐。
Lots
Of
Indents
cat <<-____________HERE
boo
____________HERE
done
done
done
回答by shellter
You can also use
你也可以使用
<Tab><Tab>cat <<-EOF >>$dir/.bashrc
#--------------------^- added a "-" char
<Tab><Tab> echo " ... "
<Tab><Tab> echo " ... "
<Tab><Tab>EOF
where EOF is now preceded with a -
character. This indicates to the shell that the closing Here-file token will be (can be) indented with tab characters. If you write, by accident, <Tab><Tab><Space>EOF
it will not match, but 0,1,2,...,100 <Tab>EOF
willmatch.
现在 EOF 前面有一个-
字符。这向 shell 表明关闭的 Here-file 标记将(可以)用制表符缩进。如果你<Tab><Tab><Space>EOF
不小心写了,它不会匹配,但 0,1,2,...,100<Tab>EOF
会匹配。
IHTH
IHTH