bash [第二个参数:找不到命令

时间:2020-04-26 17:26:30

标签: bash shell automation command mkdir

所以在使用bash shell脚本和python自动化项目时遇到了问题...

我想编写一个程序,可以帮助我使用GitHub创建新存储库。但是,在执行代码时遇到了这个问题。

本质上,我想做的是运行'create repo repo-name'并在本地创建一个新的github存储库。

function create() {
    cd
    cd path/to/python/file
    python3 gh-create-command.py $*
    if [$1 == 'repo']
    then
        <creating repository>
    fi
}

但是当我运行这段代码时,我得到了错误bash: [repo: command not found

有人可以帮我吗?

如果我要发布完整的代码,请回复。

谢谢。

编辑:完整代码

function create() { cd cd path/to/python/file python3 gh-create-command.py $* echo $1 if [ '$1' == 'repo' ] then cd 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 add . git commit -m "initial commit" git push -u origin master code . fi }

输出:回购

1 个答案:

答案 0 :(得分:2)

您缺少空格,应该是:

if [ $1 == 'repo' ]

引用所有变量以避免word splitting是一个好习惯:

if [ "$1" == 'repo' ]

,并避免Bashisms使您的代码更具可移植性。使用:

create() {

if [ "$1" = 'repo' ]