gpt4 book ai didi

linux - 意外标记附近的语法错误 "do"

转载 作者:太空宇宙 更新时间:2023-11-04 11:10:01 25 4
gpt4 key购买 nike

此 shell 脚本抛出一条错误消息:

syntax error near unexpected token do

这是我的代码

#!/bin/bash
DIRS="/home/delhi_qa/mkv/18000/marketview/log/FIFO_OPTIMISER/LOGS 1"
DEST="home/delhi_qa/Tests/Ankit/TTLOGSBACKUP"
DELETE_OLD_ZIP_FILES="no"
BASENAME=/usr/bin/basename
ZIP=/usr/bin/zip
for i in $DIRS
do
#On running this unexpected token message occurred at this line#
zipfile="${DEST}/$(${BASENAME} ${d}).zip"
echo -n "Creating $zipfile..."
if [ "$DELETE_OLD_ZIP_FILES" == "yes" ]
then
[ -f $zipfile ] && /bin/rm -f $zipfile
fi
${ZIP} -r $zipfile $d &>/dev/null && echo "Done!"
done

你能告诉我为什么吗?

最佳答案

Your input file contains carriage returns. Use dos2unix or something similar to get rid of those. – devnull

devnull 是正确的。问题的错误修订 3 通过扭曲错误消息来隐藏这一点,错误消息之前显示为

syntax error near unexpected token `do
- note the lone grave accent (`), which bash uses at the beginning of token names in messages together with an apostrophe (') at the end to quote the token.

The exact error message got to be e. g. for a script called ./do

'/do: line 8: syntax error near unexpected token `do

附加撇号出现在行首,覆盖了命令 ./do 的第一个字符。这只能由 do 后的回车引起。

关于linux - 意外标记附近的语法错误 "do",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23625397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com