首页 > 解决方案 > bash 脚本在不同的计算机上不起作用

问题描述

我在一台计算机上编写了一些脚本,但粘贴到另一台计算机上的完全相同的内容无法编译。为什么不?

脚本是:

alias push=gitPush

gitPush() {
    branch_name=$(git branch | grep '*' | sed 's/* //')
    NUM=$(echo $branch_name | grep -o '\([0-9]\+\)')

    # push to branch
    read -p 'Do you have any files to add? ' yn

    case $yn in
       [Yy]* ) echo 'Adding...'; git add .;git commit -a -m 'ITEM-'$NUM':';git commit --amend;...;;
       * ) echo 'Acceptable input: y/n/q';;
    esac
}

在 中的第一行case,我收到语法错误。但是这个确切的脚本可以在一台计算机上运行。

编辑:

这是另一个失败的脚本。

cleanBranches() {
   echo 'Cleaning branches...'
   # the line below fails with:
   # syntax error near unexpected token `'refs/heads/develop''
   IGNORE_BRANCHES=('refs/heads/develop' 'refs/heads/master')
}

标签: bashmacos

解决方案


推荐阅读