相关疑难解决方法(0)

在shell脚本中使用if elif fi

我不确定如何if在shell中进行多项测试.我在编写这个脚本时遇到了麻烦:

echo "You have provided the following arguments $arg1 $arg2 $arg3"
if [ "$arg1" = "$arg2" && "$arg1" != "$arg3" ]
then
    echo "Two of the provided args are equal."
    exit 3
elif [ $arg1 = $arg2 && $arg1 = $arg3 ]
then
    echo "All of the specified args are equal"
    exit 0
else
    echo "All of the specified args are different"
    exit 4
fi
Run Code Online (Sandbox Code Playgroud)

问题是我每次都会收到此错误:

./compare.sh:[:missing`]'找不到命令

bash shell

55
推荐指数
5
解决办法
25万
查看次数

验证是否存在提交

如何验证当前分支中是否存在具有给定sha的提交?

解析输出有很多种方法,但我需要返回布尔值的最佳方法(用于bash脚本).

例如

sha=$1
if [ -z `git magic --validate $sha` ]; then
  echo "Invalid commit sha: $sha"
  exit 1
fi
Run Code Online (Sandbox Code Playgroud)

git scripting githooks

14
推荐指数
2
解决办法
8502
查看次数

Bash/Shell脚本函数验证Git标记或提交存在并已被推送到远程存储库

我想在那里得到这个问题,看看我是否做得对.以下脚本工作,除了检查提交是否已被推送到远程仓库,我找不到正确的命令:

#!/bin/bash
set -e  # fail on first error    
verify_git_ref() {
        log "Verifying git tag or commit: \"$1\" ...."
        if git show-ref --tags --quiet --verify -- "refs/tags/$1"
        then
            log_success "Git tag \"$1\" verified...."
            GIT_TAG_OR_REF=$1
            return 0
        elif git rev-list $1>/dev/null 2>&1
        then
            log_success "Git commit \"$1\" verified...."
            GIT_TAG_OR_REF=$1
            return 0
        else
            log_error "\"$1\" is not a valid tag or commit, you must use a valid tag or commit in order for this script to continue"
            return 1
        fi …
Run Code Online (Sandbox Code Playgroud)

git bash

7
推荐指数
1
解决办法
7304
查看次数

如何检查 if/else 中是否存在标签

如何检查我的 GIT 存储库中是否存在标签。我得到一些标记名作为输入,我必须检查它是否是带有if else statement. TAG="tagname"的有效标记

我试过:

if [ git rev-parse ${TAG} >/dev/null 2>&1 ]; then
  echo "tag exists";
else
  echo "tag does not exist";
Run Code Online (Sandbox Code Playgroud)

但它没有用

git bash if-statement

7
推荐指数
2
解决办法
8500
查看次数

标签 统计

bash ×3

git ×3

githooks ×1

if-statement ×1

scripting ×1

shell ×1