Syntax error eof in backquote substitution

I'm getting an error Syntax error: EOF in backquote substitution and I don't have the faintest idea why. Would anyone mind taking a quick look? #! /bin/sh # chkconfig 345 85 60 # description: star...

I’m getting an error Syntax error: EOF in backquote substitution and I don’t have the faintest idea why. Would anyone mind taking a quick look?

#! /bin/sh
# chkconfig 345 85 60
# description: startup script for produtcrawler-router
# processname: producrawler-router

NAME=productcrawler-router
DIR=/etc/productcrawler/services
EXEC=router.py
PID_FILE=/var/run/productcrawler.pid
IEXE=/etc/init.d/productcrawler-router
RUN_AS=root

### BEGIN INIT INFO
# Provides:          productcrawler-router
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     5
# Default-Stop:      0 1 2 3 6
# Description:       Starts the productcrawler-router service
### END INIT INFO

if [ ! -f $DIR/$EXEC ]
then
        echo "$DIR/$EXEC not found."
        exit
fi

case "$1" in
  start)
        echo -n "Starting $NAME"
        cd $LDIR
        start-stop-daemon -d $DIR --start --background --pidfile $PID_FILE --make-pidfile --exec $EXEC --quiet
        echo "$NAME are now running."
        ;;
  stop)
        echo -n "Stopping $NAME"
        kill -TERM `cat $PID_FILE
        rm $PID_FILE
        echo "$NAME."
        ;;
  force-reload|restart)
        $0 stop
        $0 start
        ;;
  *)
        echo "Use: /etc/init.d/$NAME {start|stop|restart|force-reload}"
        exit 1
        ;;
esac

asked Apr 29, 2011 at 20:34

Kit Sunde's user avatar

Kit SundeKit Sunde

35.2k25 gold badges124 silver badges178 bronze badges

The syntax coloring didn’t give it away?

 stop)
       echo -n "Stopping $NAME"
       kill -TERM `cat $PID_FILE

It’s the backtick and the end of the kill line.

answered Apr 29, 2011 at 20:36

eduffy's user avatar

2

  • Печать

Страницы: [1]   Вниз

Тема: Syntax error: EOF in backquote substitution  (Прочитано 3129 раз)

0 Пользователей и 1 Гость просматривают эту тему.

Оффлайн
crp.518

При запуске скрипта со след. содержимым:
#!/bin/sh
mkdir /bk/backup
cd /bk/backup
tar -zcvf `date +%d-%m-%Y`arhiv.tar.gz /home/ilyas/data.sh

mkdir /bk/`date +%d-%m-%Y`
mv ./*.tar.gz /bk/`date +%d-%m-%Y`
chmod -Rf 777 /bk/

ftp -n 185.8.212.17 <<END_SCRIPT
quote USER root
quote PASS ****
put /bk/`date +%d-%m-%Y`/`date +%d-%m-%Y`arhiv.tar.gz `date +%d-%m-%$
quit
END_SCRIPT
эрэм эрэф /bk/`date +%d-%m-%Y`/
эрэм эрэф /bk/backup/
exit 0

вылетает data.sh: 21: data.sh: Syntax error: EOF in backquote substitution. где у меня ошибка?)

« Последнее редактирование: 25 Декабря 2013, 17:47:31 от crp.518 »


Оффлайн
Karl500

Не нужно один и тот же вопрос задавать в разных темах и разделах.


Оффлайн
crp.518

Так я подумал что тот раздел не подходит к моей проблеме и создал новую…


Оффлайн
FixNix

put /bk/`date +%d-%m-%Y`/`date +%d-%m-%Y`arhiv.tar.gz `date +%d-%m-%$

Проверьте выделенное красным, случайно там не закралась ошибка?

ubuntu 16.04 x64 — комп. на работе и ноут дома, Nautilus Nemo (2.8.7) для Unity.
Если хочешь сделать что-то хорошо, сделай это сам.


Оффлайн
victor00000

вылетает data.sh: 21: data.sh: Syntax error: EOF in backquote substitution. где у меня ошибка?)

два раза выполнить data.sh получить ошибка вот это END_SCRIPT
должно
data0.sh — END_SCRIPT0
data1.sh — END_SCRIPT1


Оффлайн
Karl500

Я в другой теме уже сказал — строка скопирована не полностью. Там должно быть еще и имя файла. Копируйте внимательнее.


Оффлайн
crp.518

put /bk/`date +%d-%m-%Y`/`date +%d-%m-%Y`arhiv.tar.gz `date +%d-%m-%$

Проверьте выделенное красным, случайно там не закралась ошибка?

#!/bin/sh
mkdir /bk/backup
cd /bk/backup
tar -zcvf `date +%d-%m-%Y`_nazvanie_arhiva.tar.gz /root/

mkdir /bk/`date +%d-%m-%Y`
mv ./*.tar.gz /bk/`date +%d-%m-%Y`
chmod -Rf 777 /bk/

ftp -n vash.udalenniftp.ru <<END_SCRIPT
quote USER user
quote PASS vashpass
put /bk/`date +%d-%m-%Y`/`date +%d-%m-%Y`_nazvanie_arhiva.tar.gz `date +%d-%m-%Y`_nazvanie_arhiva.tar.gz
quit
END_SCRIPT
эрэм эрэф /bk/`date +%d-%m-%Y`/
эрэм эрэф /bk/backup/
exit 0


  • Печать

Страницы: [1]   Вверх

When I try to import a sql file into a mysql database via ansible I get this error:

NOTIFIED: [tt-rss | import tt-rss sql] **************************************** 
failed: [mediahub.vanutsteen.nl] => {"failed": true, "item": ""}
msg: Syntax error: EOF in backquote substitution
Syntax error: Error in command substitution

I’m provisioning a FreeBSD host. This is the task:

- name: import tt-rss sql
  mysql_db: name="{{ ttrss_mysql_database }}"
    login_host="{{ ttrss_mysql_host }}"
    login_user="{{ ttrss_mysql_user }}"
    login_password="{{ ttrss_mysql_password }}"
    state=import
    target="/usr/local/www/tt-rss/schema/ttrss_schema_mysql.sql"

The error message with -vvvv:

NOTIFIED: [tt-rss | import tt-rss sql] **************************************** 
<mediahub.vanutsteen.nl> ESTABLISH CONNECTION FOR USER: leon
<mediahub.vanutsteen.nl> EXEC ['ssh', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/home/leon/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'Port=22', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'ConnectTimeout=10', 'mediahub.vanutsteen.nl', "/bin/sh -c 'mkdir -p /tmp/ansible-1386274190.6-35323313635181 && chmod a+rx /tmp/ansible-1386274190.6-35323313635181 && echo /tmp/ansible-1386274190.6-35323313635181'"]
<mediahub.vanutsteen.nl> REMOTE_MODULE mysql_db name="ttrss" login_host="mysql.vanutsteen.nl" login_user="ttrss" login_password=">0`;JU$DhQ-u0z%P_t;TSQhOC" state=import target="/usr/local/www/tt-rss/schema/ttrss_schema_mysql.sql"
<mediahub.vanutsteen.nl> PUT /tmp/tmpaVkVEi TO /tmp/ansible-1386274190.6-35323313635181/mysql_db
<mediahub.vanutsteen.nl> EXEC ['ssh', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/home/leon/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'Port=22', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'ConnectTimeout=10', 'mediahub.vanutsteen.nl', '/bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=jkjxzagyumcvdswoewonbiwwuedlagaf] password: " -u root /bin/sh -c '"'"'echo SUDO-SUCCESS-jkjxzagyumcvdswoewonbiwwuedlagaf; /usr/local/bin/python /tmp/ansible-1386274190.6-35323313635181/mysql_db; rm -rf /tmp/ansible-1386274190.6-35323313635181/ >/dev/null 2>&1'"'"''']
failed: [mediahub.vanutsteen.nl] => {"failed": true, "item": ""}
msg: Syntax error: EOF in backquote substitution
Syntax error: Error in command substitution

I’ve installed ansible on an Ubuntu laptop from the ppa:

$ ansible --version
ansible 1.4

There are a few errors in this script. They all relate to command-line syntax, most for bash, but in one case for the separate expr utility. In summary:

  • The original problem related to an unmatched ` in a backquote expression (and more generally, how to close a backquote expression and how newlines inside backquote expressions are handled by the shell).
  • Other syntax errors preventing your script from working properly relate to argument parsing in the [ construct and the expr command.

See below for details.

The Original EOF in backquote substitution Error

As Florian Diesch says (and in Helio’s answer also), the original problem was a missing ` at the end of the first backquoted expr ... command. However, the more interesting aspect of this question is why do you get that error message? This is not merely a matter of idle curiosity—understanding that helps you comprehend this and other error messages in the future.

EOF stands for end-of-file and it means there are no more data available to read—in this case, text for the bash interpreter to read. EOF is not inherently an error condition, but when an EOF is an error it usually means the interpreter thinks your program has ended prematurely—it was anticipating something, which never occurred in your program.

If the error message had said the error was an end of line in the backquote substitution, you would probably have immediately recognized the problem (provided you know that ` is called a backquote and and command substitution using a backquoted construct is also called backquote substitution).

Why does bash think the file ends too soon, rather than the line? This is because you can actually have newlines (i.e., line breaks) inside a backquote expression:

ek@Io:~$ file `which vim
> `
/usr/bin/vim: symbolic link to `/etc/alternatives/vim'

So what’s happening is that bash reads the first backquote expression as

`expr $f* $i
i=`

which is definitely not what you intended!

Then what you intended as the contents of the second backquote expression it sees outside of backquotes, and sees the following as a second backquote expression:

`
done
echo "The factorial of $num is $f"
else
echo "Enter positive number"
fi

This is also not at all what you intended, and furthermore there is no closing backquote, which causes bash to report reaching end-of-file while still inside a backquote expression (EOF in backquote substitution).

The solution is not to put a backquote at the very end of the script, of course! Instead, as others have said, simply add the missing backquote where it was supposed to be.

Note, however, that this must be `, same as the opening backquote. Although the strange formatting displayed in the output of some command-line utilities might convey the impression that what begins with ` ends with ', that is not the case. (I noticed that had at one point written a ' rather than ` for the fix.)

Closing a [ Command: The [: missing ] Error

After fixing the first problem, you got a prog4: 5: [: missing ] error.

In bash, [ is a command (and in fact there is even a separate [ executable, as unlike bash some shells don’t provide a [ builtin). Blank space must appear between it and its first argument.

Similarly, it is required to pass the closing ] of a [ command as a separate command-line argument. That is, you must have blank space before the trailing ] as well as after the leading [.

The line

if [ "$num" -ge 0]; then

should thus be rewritten to say:

if [ "$num" -ge 0 ]; then

For more details on [ syntax, see the output of help [ and help test.

1+1 vs. 1 + 1

After fixing that problem, you’ll get another error, which will look something like this (depending, perhaps, on what version of bash you are running):

bash: [: 1+1: integer expression expected

The problem is that expr does not understand 1+1 is intended to mean «the sum of 1 and 1.» It does not simplify it to 2, so the [ command that subsequently examines it doesn’t have an integer to evaluate.

Why doesn’t the expr utility know 1+1 is supposed to be interpreted as an integer, the sum of 1 and 1? This is because each number and arithmetic operator must be passed as a separate command-line argument to expr:

ek@Io:~$ expr 1+1
1+1
ek@Io:~$ expr 1 + 1
2

To fix this problem, rewrite the line

    i=`expr $i+1`

to instead say:

    i=`expr $i + 1`

nitsik

Posts: 94
Joined: Mon Nov 30, 2015 9:01 pm

Os: Debian 7x
Web: apache + nginx
Ошибка /bin/sh: 1: Syntax error: EOF in backquote substitution в Cron

Здравствуйте. При добавлении такого задания в крон через панель

Code: Select all

mysqldump -uadmin -ppass --single-transaction=1 --lock-tables=false admin| gzip -c | ncftpput -u user -p pass -c xxx.xxx.xxx.xxx /all`date +%Y-%m-%d-%H-%M-%S`.sql.gz

на e-mail приходит ошибка
/bin/sh: 1: Syntax error: EOF in backquote substitution
хотя в командной строке все отрабатывает корректно. Почему так? Заранее спасибо.
Vesta Версия:0.9.8 (amd64) на debian


skurudo

VestaCP Team
Posts: 8099
Joined: Fri Dec 26, 2014 2:23 pm
Contact:

Re: Ошибка /bin/sh: 1: Syntax error: EOF in backquote substitution в Cron

Post

by skurudo » Sun Mar 05, 2017 8:46 pm

Вероятно есть сложности при парсинге этого хозяйства.
А в чем сложность создать отдельный sh-файл и в кроне ссылаться на него?


nitsik

Posts: 94
Joined: Mon Nov 30, 2015 9:01 pm

Os: Debian 7x
Web: apache + nginx
Re: Ошибка /bin/sh: 1: Syntax error: EOF in backquote substitution в Cron

Post

by nitsik » Tue Mar 07, 2017 4:01 pm

Так и сделал, спасибо)


skurudo

VestaCP Team
Posts: 8099
Joined: Fri Dec 26, 2014 2:23 pm
Contact:

Re: Ошибка /bin/sh: 1: Syntax error: EOF in backquote substitution в Cron

Post

by skurudo » Thu Mar 09, 2017 12:00 pm

Отлично :)

Я просто поясню, поскольку крон есть и у админа, и у пользователя, давать пихать туда все подряд — слегка самоуверенно. Именно поэтому часть символов может экранироваться. В итоге в крон попадает не то, что хотелось бы. Именно поэтому при длинных конструкциях гораздо проще делать отдельный bash-файлик и запускать его.



  • Home
  • Forum
  • The Ubuntu Forum Community
  • Ubuntu Official Flavours Support
  • New to Ubuntu
  • [SOLVED] /etc/default/grub: 33: Syntax error: EOF in backquote substitution ;error please help

  1. /etc/default/grub: 33: Syntax error: EOF in backquote substitution ;error please help

    Hey all

    I was following the guide for sorting my poor resolution on plymouth (http://jechem.blogspot.com/2011/04/f…ubuntu-on.html) when I follow the instructions I get this error when trying to update grub

    Code:

    /etc/default/grub: 33: Syntax error: EOF in backquote substitution

    I think it is because the guide says to alter the grub file with the following lines;

    Code:

    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nomodeset video=uvesafb:mode_option=1024x768-24,mtrr=3,scroll=ywrap

    Which I (now) notice is minus a set of quote marks.

    Any body out there know if this is the problem, and if so where do I put the » ??

    Hope someone can help.

    Mike

    Dell Inspiron 1501 AMD Sempron, 4GB RAM, 120GB HDD, running 14.04 64Bit
    Dell Latitude D830 Centrino duo 4GB RAM 320GB HDD, running 13.10 64Bit
    Raspberry Pi running Rasbian
    Ubuntu User #32384


  2. Re: /etc/default/grub: 33: Syntax error: EOF in backquote substitution ;error please

    Solved

    I found the answer elsewhere. The quotes go at the end of the line.

    Thanks for looking.

    Mike

    Dell Inspiron 1501 AMD Sempron, 4GB RAM, 120GB HDD, running 14.04 64Bit
    Dell Latitude D830 Centrino duo 4GB RAM 320GB HDD, running 13.10 64Bit
    Raspberry Pi running Rasbian
    Ubuntu User #32384


  3. Smile Re: /etc/default/grub: 33: Syntax error: EOF in backquote substitution ;error please

    Quote Originally Posted by migs73
    View Post

    Solved

    I found the answer elsewhere. The quotes go at the end of the line.

    Thanks for looking.

    Mike

    Thanks
    +1 It worked for me


Bookmarks

Bookmarks


Posting Permissions

Понравилась статья? Поделить с друзьями:
  • Syntax error converting the varchar value to a column of data type int
  • Syntax error control character unexpected
  • Syntax error continue not properly in loop
  • Syntax error command unrecognized the server response was
  • Syntax error code 1 while compiling