Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

What does readonly mean or do in this case? I have never seen or heard of it.

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

Also, would the final value of b at the end be 25?

share|improve this question
3  
run it and see it.it will help you for sure in the long way. –  user917279 Nov 1 '13 at 8:50

1 Answer 1

It makes the variable read only. From 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.

$b would still return "a". As an example:

$ a=1
$ a=2
$ readonly b=1
$ b=2
bash: b: readonly variable
$ echo "$b"
1
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.