这个脚本中发生了什么-Bash脚本
因此,我找到并修复了这些错误。现在我得到了不同的错误。有人能看完我的脚本并指出或修复你看到的所有错误吗?我是bash新手,没有得到这些错误的一半。例如:这个脚本中发生了什么-Bash脚本,bash,shell,Bash,Shell,因此,我找到并修复了这些错误。现在我得到了不同的错误。有人能看完我的脚本并指出或修复你看到的所有错误吗?我是bash新手,没有得到这些错误的一半。例如: $ composerrun.sh ./composerrun.sh: line 2: checkForComposerJson: command not found ./composerrun.sh: line 27: syntax error near unexpected token `)' ./composerrun.sh: line 2
$ composerrun.sh
./composerrun.sh: line 2: checkForComposerJson: command not found
./composerrun.sh: line 27: syntax error near unexpected token `)'
./composerrun.sh: line 27: ` [Nn]*) '
当我跑步时:
#!/bin/bash
# We need to see if the AisisCore/ Directory exists.
# If it doesn't we will try and create it for you.
# Then to be safe - we check if it exists.
function checkForAisisCore {
if [[-d "AisisCore/"]]
then
return 0;
else
read -p "Would you like us to create the directory?" yn,
case $yn in
[[Yy]]*)
mkdir "AisisCore/";
if [[-d "AisisCore/"]]
then
return 0;
else
echo "We could not create the directory as you requested";
return 1;
end
;;
[[Nn]]*)
return 1;
;;
*)
echo "Please put in either yes or no";
esac
fi
}
# We check for the aisis-core inside of vender inside of adam.balan.
# If it exists return true.
# If Not, then alert the user and return false.
function checkForVendor(){
if [[-d "vender/adam.balan/aisis-core/"]]
then
return 0;
else
echo "Something is wrong. We could not find the vendor/ folder. Please check that you are running this script inside of your theme or project folder.";
return 1;
fi
}
# We need to know if composer.json exists.
# If it does we return true.
# If not - we alert the user.
function checkForComposerJson(){
if [[-f "composer.json"]]
then
return 0;
else
echo "You need composer.json with appropriate information about AisisCore";
return 1;
fi
}
# ================================ [ Core ] ================================
# Core program.
#
# Check if the composer.json and AisisCore/ exist.
# Run composer install.
# Check for vendor folder.
# If all is good - echo Found Vendor and exit. (For now).
if checkForComposerJson && checkForAisisCore
then
composer install
if checkForVendor
then
echo "Found vendor"; exit;
fi
fi
我肯定有数百个错误和问题,但我看不到它们,因为我不知道bash。不过,我认为我走对了方向。我怎么能用第二双眼睛看这个剧本,就像“你在干什么…”
在使用函数之前先声明它们。用双分号(
;
)分隔大小写子句。与[
和]
相比,您更喜欢[[
和]
(请参阅),因为它们可以减少惊喜。在使用函数之前先声明函数。用双分号(;
)分隔大小写子句。与[
和]
相比,更喜欢[[
和]
(请参见),因为它们可以减少惊喜。好的,我更新了代码示例以更好地反映这一点,但仍然会出现相同的错误,减去/composerrun.sh:line 2:checkForComposerJson:command not found
第27行的错误是因为在Yy条件之后,bash希望您添加一行,其中只包含代码>在启动Nn条件之前。在通配符大小写之前也是一样的我认为他们应该去哪里,就像你说的,但现在bash讨厌他们。。。它就像意外的标记“;”代码>@LogicLooking您已经超出了方括号的位置。在case语句中,[Yy]
表示与Y
或Y
匹配的模式。在if语句中,[[…]
是一个bash
条件表达式,它比test
/[
命令更健壮。@chepner-Oh-所以[[]
应该用[]重复
??对于Yy和Nn,如果是这种情况,它仍然不喜欢;
好的,我更新了代码示例以更好地反映这一点,但它仍然得到相同的错误,减去/composerrun.sh:line 2:checkForComposerJson:command not found
第27行的错误是因为在Yy条件之后,bash希望您添加lin在开始Nn条件之前,只使用
;
;。在通配符大小写之前也是如此。好吧,所以我设法将;添加到我认为它们应该去的地方,就像你说的,但现在bash讨厌它们……就像意外标记“;”@LogicLooking你已经超出了方括号。在case语句中,[Yy]
表示与Y
或Y
匹配的模式。在if语句中,[…]
是一个bash
条件表达式,它是测试
/[
命令的一个更健壮的替代方法。@chepner-Oh-所以[[]]
应该用[]替换[]
?对于Yy和Nn,如果是这种情况,它仍然不喜欢;
阅读页面并清理空白–上面的一些是语法错误。阅读页面并清理空白–上面的一些是语法错误。