我在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
你能解决这个问题吗?
感谢。
答案 0 :(得分:0)
在Bash if
语句中;
需要then
,如果写在一行上的话。
或者你可以写
if [ -f ${ocpath}/.htaccess ] then
分两行:
if [ -f ${ocpath}/.htaccess ]
then