shell脚本出错:syntax error near unexpected token `fi'

sh/bash/dash/ksh/zsh等Shell脚本
回复
lysygyy
帖子: 5
注册时间: 2012-06-14 14:00

shell脚本出错:syntax error near unexpected token `fi'

#1

帖子 lysygyy » 2012-06-14 14:09

export

CODESIGN_ALLOCATE=/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platf

orm/Developer/usr/bin/codesign_allocate
if [ "${PLATFORM_NAME}" == "iphoneos" ] || [ "${PLATFORM_NAME}" ==

"ipados" ]; then
/Xcode.app/Contents/Developer/iphoneentitlements/gen_entitlements.py

"my.company.${PROJECT_NAME}" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/

${PROJECT_NAME}.xcent";
codesign -f -s "iPhone Developer" --entitlements

"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}.xcent"

"${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/"

fi

以上为运行的脚本,请问哪里错了啊,本人第一次接触shell,不懂啊。
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: shell脚本出错:syntax error near unexpected token `fi'

#2

帖子 eexpress » 2012-06-14 14:14

你这是分行的?还是不分行的?不分行,需要加;号。
● 鸣学
lysygyy
帖子: 5
注册时间: 2012-06-14 14:00

Re: shell脚本出错:syntax error near unexpected token `fi'

#3

帖子 lysygyy » 2012-06-14 14:18

eexpress 写了:你这是分行的?还是不分行的?不分行,需要加;号。
不太明白你的意思,这不就是if then fi语句嘛,能不能帮忙改一下啊!
lysygyy
帖子: 5
注册时间: 2012-06-14 14:00

Re: shell脚本出错:syntax error near unexpected token `fi'

#4

帖子 lysygyy » 2012-06-14 14:25

export

CODESIGN_ALLOCATE=/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
if [ "${PLATFORM_NAME}" == "iphoneos" ] || [ "${PLATFORM_NAME}" == "ipados" ]; then
/Xcode.app/Contents/Developer/iphoneentitlements/gen_entitlements.py "my.company.${PROJECT_NAME}" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}.xcent";
codesign -f -s "iPhone Developer" --entitlements "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}.xcent" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/"

fi

改成了上面的脚本,还是不行啊,还是提示错误:
/Users/mahmood1/Library/Developer/Xcode/DerivedData/HYGisManager-clgaxawbmlqfidbpvgnkgkmjmbca/Build/Intermediates/HYGisManager.build/Release-iphonesimulator/HYGisManager.build/Script-F267E10C158984970053F892.sh: line 6: syntax error near unexpected token `fi'
/Users/mahmood1/Library/Developer/Xcode/DerivedData/HYGisManager-clgaxawbmlqfidbpvgnkgkmjmbca/Build/Intermediates/HYGisManager.build/Release-iphonesimulator/HYGisManager.build/Script-F267E10C158984970053F892.sh: line 6: `fi'
Command /bin/sh failed with exit code 2
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: shell脚本出错:syntax error near unexpected token `fi'

#5

帖子 eexpress » 2012-06-14 14:29

你按照code贴吧。看不出。
if [ xx ] then; yyyy; fi
● 鸣学
lysygyy
帖子: 5
注册时间: 2012-06-14 14:00

Re: shell脚本出错:syntax error near unexpected token `fi'

#6

帖子 lysygyy » 2012-06-14 14:32

怎么没人回答呢?急呀!先顶上去再说!
lysygyy
帖子: 5
注册时间: 2012-06-14 14:00

Re: shell脚本出错:syntax error near unexpected token `fi'

#7

帖子 lysygyy » 2012-06-14 14:34

代码: 全选

export

CODESIGN_ALLOCATE=/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
if [ "${PLATFORM_NAME}" == "iphoneos" ] || [ "${PLATFORM_NAME}" == "ipados" ]; then
/Xcode.app/Contents/Developer/iphoneentitlements/gen_entitlements.py "my.company.${PROJECT_NAME}" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}.xcent";
codesign -f -s "iPhone Developer" --entitlements "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}.xcent" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/"

fi
头像
naturalaw
帖子: 1360
注册时间: 2011-09-06 22:04

Re: shell脚本出错:syntax error near unexpected token `fi'

#8

帖子 naturalaw » 2012-06-17 3:05

ee的意思很明白了的嘛。
两种写法
$ if [ 1 -gt 0 ];then
> echo hi
> fi
hi
$ if [ 1 -gt 0 ]
> then echo hi
> fi
hi
  • The eternal law
chenbiren
帖子: 3
注册时间: 2011-08-09 17:04

Re: shell脚本出错:syntax error near unexpected token `fi'

#9

帖子 chenbiren » 2012-07-14 15:13

你确定是bash脚本?不是C shell TC shell其他的像C shell就不是fi
chenbiren
帖子: 3
注册时间: 2011-08-09 17:04

Re: shell脚本出错:syntax error near unexpected token `fi'

#10

帖子 chenbiren » 2012-07-14 15:30

你确定是bash脚本?不是C shell TC shell其他的像C shell就不是fi
aerofox
帖子: 1453
注册时间: 2008-05-24 8:30

Re: shell脚本出错:syntax error near unexpected token `fi'

#11

帖子 aerofox » 2012-07-15 6:44

有可能脚本文件采用了DOS格式的换行,不过要 fi 后正好有个空格才行吧。最好把脚本文件已附件的形式贴上来看看。

与报的错无关的问题:export 应该与下面的赋值在同一行。
回复