gpt4 book ai didi

bash - error= 和 error ='' 的区别

转载 作者:行者123 更新时间:2023-11-29 09:09:31 25 4
gpt4 key购买 nike

在 Bash 中,这两个变量定义有区别吗?

error=
error=''

在空虚/未设置时测试它们似乎表明它们是相等的,但我仍然想确定。

最佳答案

简短回答:不,根本没有区别。 引号在解析过程中被去除。


来自Variable Assignment section of the POSIX reference :

In the shell command language, a word consisting of the following parts:

varname=value

下面几行你会看到:

If value is not specified, the variable shall be given a null value.

检查这个(在 Bash 中):

$ variable1=
$ variable2=''
$ declare -p variable{1,2}
declare -- variable1=""
declare -- variable2=""

它们看起来确实一模一样!

关于bash - error= 和 error ='' 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32839531/

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