所以在使用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
}
输出:回购
答案 0 :(得分:2)
您缺少空格,应该是:
if [ $1 == 'repo' ]
引用所有变量以避免word splitting是一个好习惯:
if [ "$1" == 'repo' ]
,并避免Bashisms使您的代码更具可移植性。使用:
create() {
和
if [ "$1" = 'repo' ]