0

我们如何检查变量是否 是只读的?请举例说明

4

2 回答 2

0

您没有提供有关您在说什么的任何信息,但我想您想检查 bash 中的变量。

如果是这种情况,这篇文章可能会对您有所帮助:Test if a variable is read-only

在以后的问题中,我建议您提供有关您正在处理的环境的更多信息。

于 2021-07-01T11:21:20.940 回答
0

如果您键入不带参数的命令readonly,它将打印只读变量的列表。所以你可以这样写:

readonly PI=3.14
PO=3.14
if [ "$(readonly | grep -w PI)" != "" ] ; then echo read-only ; else echo not read-only ; fi
if [ "$(readonly | grep -w PO)" != "" ] ; then echo read-only ; else echo not read-only ; fi

这将导致以下输出:

read-only
not read-only
于 2021-07-01T11:25:56.540 回答