gpt4 book ai didi

linux - 意外标记 `fi' 附近出现语法错误(运行脚本)

转载 作者:太空宇宙 更新时间:2023-11-04 05:59:56 25 4
gpt4 key购买 nike

我在 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

你能帮我解决这个问题吗?

谢谢。

最佳答案

在 Bash 中,如果写在一行中,if 语句需要 ;then 之前。

或者你可以写

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

分两行:

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

关于linux - 意外标记 `fi' 附近出现语法错误(运行脚本),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48560735/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com