Thursday, May 17, 2012
1:25 AM

Bash Script: Creating and using Read-only variables

Here is an simple bash script showing the trick to create the read-only variable, feel free to copy and use this script.

$ cat declare.sh
#!/bin/bash

# Declare the variable as readonly
declare -r AGE=25
echo $AGE

# Try to change the value of this readonly variable
# you should get an error message
AGE=34
echo $AGE

Output: $ ./declare.sh
./declare.sh
25
./declare.sh: line 9: AGE: readonly variable
25


0 comments:

Post a Comment

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.