how to unset the readonly variable


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users how to unset the readonly variable
# 1  
Old 09-11-2007
how to unset the readonly variable

Hi All,


May be this is a very simple question...

[trainee@Venus trainee]$ b=8
[trainee@Venus trainee]$ readonly b
[trainee@Venus trainee]$ echo $b
8
[trainee@Venus trainee]$ b=90
-bash: b: readonly variable
[trainee@Venus trainee]$ unset b
-bash: unset: b: cannot unset: readonly variable


I m not able to change the readonly mode of variable b
Please help me out..

Thanks
Nidhi
# 2  
Old 09-11-2007
Tha man pages for bash says, once a variable is marked as readonly, it cannot be unset.

Code:
             typeset -r     Make names readonly.  These names cannot then be  assigned values by subsequent assignment statements or unset.

Also unset says

Code:
       unset [-fv] [name ...]
              For each name, remove the corresponding variable or function.  If
              no  options  are  supplied,  or the -v option is given, each name
              refers to a shell  variable.   Read-only  variables  may  not  be
              unset.

Your best option would be to kill the shell, or run the commands within a subshell. Something like

Code:
[/tmp]$ {(b=8; readonly b; echo "-$b-"); b=90; echo "[$b]"; unset b; echo "[[$b]]";}
-8-
[90]
[[]]

# 3  
Old 09-12-2007
Thanks Vino...
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Where unset command locates?

Hi, Can someone tell what is the path for "unset", I tried "which" command but getting below error # which unset /usr/bin/which: no unset in (/usr/lib/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin/:/root/bin) (9 Replies)
Discussion started by: stew
9 Replies

2. UNIX for Dummies Questions & Answers

Unset environement variable

Hi, I have the following line in the script unset _SET_ENV_AA unset _SETENV but where I can check the value for this environement variable (2 Replies)
Discussion started by: stew
2 Replies

3. UNIX for Advanced & Expert Users

Error due to unset variable - Solaris vs GNU Linux - Help needed

Hi all, I have a weird problem. When i run the below code in SunOS and Linux i get different outputs ==== $ cat tst.ksh #!/bin/ksh echo "Abc" > $LOG_FILE echo "Ret - $?" ===== In Solaris $ ./tst.ksh Abc Ret - 0 In GNU Linux (1 Reply)
Discussion started by: NickKnight
1 Replies

4. Shell Programming and Scripting

Unset variable with characters in value

I have a script with a $PASSWORD variable. I unset it right after using it, just to minimize the chance it could be left around for a snooper. That worked just fine... until I used a password with a value of "P@ssw0rd" Now, unset (even with -f, even with the variable enquoted) tells me: unset:... (1 Reply)
Discussion started by: jnojr
1 Replies

5. Shell Programming and Scripting

removing readonly behaviour from variable

Hi, I am new to shell programming. I just wanted to know if I set a variable to readonly. How do I revert it back to normal. name="some_name" readonly name Now I want to make name variable back to it normal, on which I can perform write operation too. Thanks (3 Replies)
Discussion started by: dearvivekkumar
3 Replies

6. Shell Programming and Scripting

[ask] about unset variables

I'm wondering, is the number of variables will affect execution time of my bash script or maybe affect the cpu workload, cpu memory, etc ? If I create so many variables, should I unset each one of that variables after I used them or after I think they are no longer needed? and if my script... (2 Replies)
Discussion started by: 14th
2 Replies

7. UNIX for Advanced & Expert Users

unset .bashrc

Could someone please tell me how to unset your .bashrc? I have tried all of these. I can't find anything useful from google. unset -f .bashrc unset .bashrc (9 Replies)
Discussion started by: cokedude
9 Replies

8. Shell Programming and Scripting

How do I define a particular dir in PATH variable and then unset that dir

How do I define a particular dir in front of PATH variable and then run some job and then at the end of job SET the PATH variable to original? in a script, WILL something like this work: ORIG_PATH=$PATH export PATH=/dir1/dir2:$PATH RUN SOME JOBS ..... unset PATH EXPORT... (2 Replies)
Discussion started by: Hangman2
2 Replies

9. Shell Programming and Scripting

Is there any way to set env variable in top level Makefile and unset when done

Hello I have compilation directory structure the top level Makefile is the one that contains all the sub directories I want to set in this Makefile env variable say : setenv OPTIMIZATION_LEVEL "1" and when all the sub directories done compiling it will set this variable to different lavel... (0 Replies)
Discussion started by: umen
0 Replies
Login or Register to Ask a Question