gpt4 book ai didi

linux - bash 参数相等性检查的意外输出

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:32:38 25 4
gpt4 key购买 nike

<分区>

我在 Bash 脚本中进行了基本的字符串相等性检查,但输出与预期不同。

要重现,请将下面的代码复制到可执行文件(在我下面的示例中称为“部署”)

#!/bin/bash

echo $1

if [[ "$1" -eq "--help" ]] || [[ "$1" -eq "-h" ]]; then
echo "hello"
fi


如果我这样运行脚本:

./deploy -h

输出是:

-h
hello

如果我这样运行脚本:

./deploy --help

输出是:

-help

为什么条件语句不解析为真?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com