Syntax error near unexpected token `elif'

前端 未结 5 2046
悲&欢浪女
悲&欢浪女 2021-01-03 22:01
./chkf: line 30: syntax error near unexpected token `elif\'
\'/chkf: line 30: `elif [ -f \"$object\" ] ; then


if [ -d \"$object\" ] ; then
    message=\"$message a         


        
相关标签:
5条回答
  • 2021-01-03 22:24

    It's your line endings. Transferring it from Windows has left the CR/LF line endings on.

    When I create a script then manually add the CR characters, I get exactly the same error:

    qq.sh: line 3: syntax error near unexpected token `elif'
    'q.sh: line 3: `elif [ 1 == 1 ] ; then
    

    You can fix it by removing the CR character from CR/LF line endings.

    cat script.sh | sed '/\015/d' >newscript.sh
    
    • CR character correspond to \015 octal representation as listed in ASCII
    0 讨论(0)
  • 2021-01-03 22:31

    it looks like you've got the "dos problem", embedded control-M's in your file. fix it with sed:

    
    sed -i 's/\r//' chkf
    
    0 讨论(0)
  • 2021-01-03 22:34

    Now that you've added the additional error message, I have a thought: the ^M is \r, which is the Mac OS X line ending or part of the Windows line ending - Linux uses \n only as EOL. If you edit in vim, you should be able to see the ^M if it's not right through the file.

    0 讨论(0)
  • 2021-01-03 22:40

    Two ways to resolve this

    1) Using Sed:-

    Syntax

    sed -i 's/\r//' filename.txt
    

    2) Using dos2unix command

    Syntax

    dos2unix fileName.txt fileName.txt
    
    0 讨论(0)
  • 2021-01-03 22:44

    I got below error in my mail when i set up cron for magento.

    /bin/sh: -c: line 0: syntax error near unexpected token `newline'
    /bin/sh: -c: line 0: `php /home/pooja/public_html/magento/journal/cron1.php >'
    

    I found solution for that is i remove newline space from my cron1.php file. and its work.

    (source)

    0 讨论(0)
提交回复
热议问题