読み取り専用変数を削除または変更できますか?

読み取り専用変数を削除または変更できますか?

Bashで変数を設定readonlyしましたがunset。読み取り専用変数を削除する方法は?

[root@test ~]# readonly xyz=2

[root@test ~]# echo $xyz
2

[root@test ~]# xyz=44
-bash: xyz: readonly variable

[root@test ~]# unset xyz
-bash: unset: xyz: cannot unset: readonly variable

ベストアンサー1

これは読み取り専用変数の機能ですbash。読み取り専用変数は変更または設定解除できません。

bashマニュアルでdeclare -r(と同じreadonly)について:

-r
名前を読み取り専用に設定します。この名前は後続の割り当てステートメントでは割り当てられません。または設定されていません

おすすめ記事