意外标记'fi'附近的语法错误(运行脚本)

时间:2018-02-01 10:39:45

标签: linux bash ubuntu

我在Ubuntu Server中运行脚本时遇到问题。 我想执行这个命令:

sudo ./grantperm.sh

但是我收到了这个错误:

“Creating“chmod“chown“chmod/chown./grantperm.sh: line 29: syntax error near unexpected token `fi'
./grantperm.sh: line 29: `fi'

代码以这种方式编写:

#!/bin/bash
ocpath='/var/www/nextcloud'
htuser='www-data'
htgroup='www-data'
rootuser='root'

printf “Creating possible missing Directories\n”
mkdir -p $ocpath/data
mkdir -p $ocpath/updater

printf “chmod Files and Directories\n”
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750

printf “chown Directories\n”
chown -R ${rootuser}:${htgroup} ${ocpath}/
chown -R ${htuser}:${htgroup} ${ocpath}/apps/
chown -R ${htuser}:${htgroup} ${ocpath}/config/
chown -R ${htuser}:${htgroup} ${ocpath}/data/
chown -R ${htuser}:${htgroup} ${ocpath}/themes/
chown -R ${htuser}:${htgroup} ${ocpath}/updater/

chmod +x ${ocpath}/occ

printf “chmod/chown .htaccess\n”
if [ -f ${ocpath}/.htaccess ] then
chmod 0644 ${ocpath}/.htaccess
chown ${rootuser}:${htgroup} ${ocpath}/.htaccess
fi
if [ -f ${ocpath}/data/.htaccess ] then
chmod 0644 ${ocpath}/data/.htaccess
chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess
fi

你能解决这个问题吗?

感谢。

1 个答案:

答案 0 :(得分:0)

在Bash if语句中;需要then,如果写在一行上的话。

或者你可以写

if [ -f ${ocpath}/.htaccess ] then

分两行:

if [ -f ${ocpath}/.htaccess ]
then