我已经检查了上一篇关于此错误的文章。仍然没有得到解决办法的工作。这是我的bash脚本。有人能帮我解决这个问题吗。我已经使用https://www.shellcheck.net/看到任何错误。我没有找到任何东西。
Dockerfunctiontest.sh: 2: Dockerfunctiontest.sh: Syntax error: "(" unexpected#!/bin/bash
function BuildSimpleContainer ()
{
docker search mariadb
docker pull mariadb:latest
docker run --name mariadbtestfour -e MYSQL_ROOT_PASSWORD=mypass -d mariadb --log-bin --binlog-format=MIXED
docker exec -it mariadbtest bash
apt-get -qq update
apt-get -qq -y install curl
apt-get -qq -y install wget
apt-get update
apt-get install apt-transport-https
apt-get update
cd /home
mkdir mdsd
cd mdsd/
wget '<blob url to pfx file>'
echo "certififcate Downloaded"
wget '<blob url file1>'
echo "file1 Downloaded"
wget 'blob url file2'
echo "file2 Downloaded"
}
BuildSimpleContainer发布于 2018-02-26 20:13:47
我的猜测是,您不以Bash脚本的形式运行此脚本,而是使用其他shell,它不接受这种语法。例如:sh。
正如您在Shellcheck中所看到的,正如Bash在我的Debian上的man所确认的,这个语法是正确的:
name () compound-command [redirection]
function name [()] compound-command [redirection]您正在使用上述两种方法中的第二种方法,您的compound-command是{...}大括号的内容。就man bash的情况而言,这是很好的。但是,也有反对这种结构的声音,就像在另一个答案下面的约翰·穆恩评论中的链接中。在指向Greg的Wiki的链接中,这个答案又出现了。
回到您的问题,考虑到脚本的名称,即Dockerfunctiontest.sh,我可能认为sh和bash之间没有太大区别。您可能使用以下命令运行脚本:
sh Dockerfunctiontest.sh虽然使用以下两种方法运行它是合理的:
bash Dockerfunctiontest.sh或
./Dockerfunctiontest.sh最后一个脚本根据脚本中的第一行选择解释器,即:
#!/bin/bash当脚本中命名的解释器是Bash时,为什么不以正确的方式命名文件呢?
Dockerfunctiontest.bash未来不那么混乱了。
发布于 2022-03-07 12:44:35
很简单!只需从声明中删除(和),然后再试一次,就像“函数foo(){}”与“foo(){}”的区别所说的。
https://unix.stackexchange.com/questions/426778
复制相似问题