【问题标题】:bash [second-argument: command not found [duplicate]bash [第二个参数:找不到命令[重复]
【发布时间】:2020-08-10 04:37:04
【问题描述】:

所以我在使用 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 }

输出:回购

【问题讨论】:

  • [ 后面缺少一个空格

标签: bash shell automation command mkdir


【解决方案1】:

您缺少空格,应该是:

if [ $1 == 'repo' ]

最好引用所有变量以避免word splitting

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

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

create() {

if [ "$1" = 'repo' ]

【讨论】:

  • 您好,我添加了空格,但是 if 语句中的内容仍然没有运行。
  • 这意味着"$1" 不等于'repo'。在 if 行之前检查它的值:echo "$1".
  • 我做到了,它在终端中提供了回购
  • 您可以通过编辑问题并发布您得到的输出来显示您更新的脚本吗?
  • 当然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 } 输出:回购
猜你喜欢
  • 2013-05-17
  • 1970-01-01
  • 2017-02-23
  • 2012-06-06
  • 2013-03-22
  • 2015-01-22
  • 2022-11-24
  • 2012-09-18
  • 2020-10-10
相关资源
最近更新 更多