bash[第二个参数:未找到命令]
所以我在用bash shell脚本和python自动化我的项目时遇到了一个问题 我想编写一个程序,帮助我使用GitHub创建新的存储库。但是,我在执行代码时遇到了这个问题 基本上,我想做的是运行“bash[第二个参数:未找到命令],bash,shell,automation,command,mkdir,Bash,Shell,Automation,Command,Mkdir,所以我在用bash shell脚本和python自动化我的项目时遇到了一个问题 我想编写一个程序,帮助我使用GitHub创建新的存储库。但是,我在执行代码时遇到了这个问题 基本上,我想做的是运行“createrepo-repo-name”并在本地创建一个新的github存储库 function create() { cd cd path/to/python/file python3 gh-create-command.py $* if [$1 == 'repo']
createrepo-repo-name
”并在本地创建一个新的github存储库
function create() {
cd
cd path/to/python/file
python3 gh-create-command.py $*
if [$1 == 'repo']
then
<creating repository>
fi
}
函数创建(){
光盘
cd路径/to/python/file
python3 gh-create-command.py$*
如果[$1=='回购']
然后
fi
}
但是当我运行这段代码时,我得到一个错误,bash:[repo:command not found
有人能帮我吗
请回复,如果我应该张贴完整的代码
谢谢
编辑:完整代码
函数创建(){
光盘
cd路径/to/python/file
python3 gh-create-command.py$*
回声1美元
如果['$1'=='repo']
然后
光盘
cd路径/
mkdir$2
cd$2
touch README.md
初始化
光盘
cd路径/to/python/file
python3 gh-create-online-repo.py$*
git远程添加源'https://github.com/advaitvariyar/2美元,吉特'
git添加。
git提交-m“初始提交”
git-push-u源主机
代码。
fi
}
输出:repo您缺少空格,应该是:
if [ $1 == 'repo' ]
引用所有变量是一种很好的做法,以避免:
为了避免bashism,使您的代码更易于移植,请使用:
create(){
及
if[“$1”='repo']
您在[
之后缺少一个空格您好,我添加了空格,但是if语句中的内容仍然没有运行。这意味着“$1”
不等于'repo'
。请在if行前面检查它的值:echo“$1”
。我这样做了,它最终给出了repo。您可以通过编辑问题来显示更新的脚本并发布您得到的输出吗?当然函数create(){cd cd-path/to/python/file python3 gh-create-command.py$*echo$1 if['$1'='repo']然后是cd path/mkdir$2 cd$2 touch README.md git init cd..cd path/to/python/file python3 gh-create-online-repo.py$*git remote add origin'https://github.com/advaitvariyar/$2.git'git添加.git提交-m“初始提交”git push-u origin master code.fi}
output:repo
if [ "$1" == 'repo' ]