読み取り専用とはどういう意味ですか?

読み取り専用とはどういう意味ですか?

この文脈では、読み取り専用とは何を意味または実行するのですか?私はそれを見たことも聞いたこともありません。

a="testString"; b=a; readonly b; b=25;

そして最終的にbの最終値は25になりますか?

ベストアンサー1

変数を読み取り専用にします。からhelp readonly

readonly: readonly [-aAf] [name[=value] ...] or readonly -p
    Mark shell variables as unchangeable.

    Mark each NAME as read-only; the values of these NAMEs may not be
    changed by subsequent assignment.  If VALUE is supplied, assign VALUE
    before marking as read-only.

    Options:
      -a    refer to indexed array variables
      -A    refer to associative array variables
      -f    refer to shell functions
      -p    display a list of all readonly variables and functions

    An argument of `--' disables further option processing.

    Exit Status:
    Returns success unless an invalid option is given or NAME is invalid.

$bb が読み取り専用で生成されると、常に「1」が返されます。たとえば、

$ a=1
$ a=2
$ readonly b=1
$ b=2
bash: b: readonly variable
$ echo "$a"
2
$ echo "$b"
1

おすすめ記事