removing readonly behaviour from variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting removing readonly behaviour from variable
# 1  
Old 07-01-2012
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.

Code:
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
# 2  
Old 07-01-2012
You cannot mark it un-readonly, you are stuck with it until the process that created it is gone. readonly is used on variables like TMOUT, which are set in /etc/profile and meant to have "forever" duration for any user that logs in.

This is what POSIX says about readonly:

readonly
# 3  
Old 07-01-2012
For scripting purposes you would have to seed a variable with a new name and continue the script with the new name.
Code:
new_var="${name}"

Obviously if a special variable like $PATH was read-only, the new variable would not inherit the special meaning.
# 4  
Old 07-02-2012
Thanks for your replies!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Odd Behaviour for Set and IFS variable

Ok, so I'm playing around with delimters and reading files. and I came across this behaviour that I thought was a bit odd, regarding how the set command takes values... If I run this: IFS=$'-' #Assigns the - as the default delimiter for bash set I-love-my-gf-a-lot #uses set to put a bunch of... (1 Reply)
Discussion started by: Lost in Cyberia
1 Replies

2. Shell Programming and Scripting

Removing multiple values from a variable

Hi I have a requirement like # e=`ls | grep -e"test" | awk -F " " '{print $1}'` (0) root @ ptxfv3: / # echo $e test test.xml From this i need to grep the word "test" alone i.e., it is occuring twice I need only one among them Please help (6 Replies)
Discussion started by: Priya Amaresh
6 Replies

3. Shell Programming and Scripting

Perl removing strings from a variable value

Dear all, I have a variable called $abc, which the value is something like below, *** *********** : ***** where * can be anything. I need to remove all but the final characters until last whitespace. example grd groupstudy : tutor6/7 becomes tutor6/7 something like if... (2 Replies)
Discussion started by: tententen
2 Replies

4. Shell Programming and Scripting

Removing a character from a variable and assigning it to another variable?

Hi folks. I have this variable called FirstIN that contains something like this: 001,002,003,004... I am trying to assign the content of this variable into ModifiedIN but with the following format : 001 002 003 004...(changing the commas for spaces) I thought about using sed but i am not... (17 Replies)
Discussion started by: Stephan
17 Replies

5. UNIX for Dummies Questions & Answers

removing new line from the shell variable value

I have a small doubt that, how to chomp the new line from the bash shell variable value. In perl, i will do chomp, but how to do it in bash -- shell programming. When i redirect the date output i have a new line in it, which i would want to remove, how to do ?! (5 Replies)
Discussion started by: thegeek
5 Replies

6. Shell Programming and Scripting

Removing leading spaces from the variable value.

Hi All, I am trying to replace the value of a xml tag with a new one. But, the existing value in the xml contain leading spaces and I tried to remove that with different sed commands but all in vain. For replacing the value I wrote the command in BOLD letters below: bash-3.00$... (3 Replies)
Discussion started by: khedu
3 Replies

7. Shell Programming and Scripting

Removing character ' from a variable

Hello there, I have a variable in the form of '/example/file.txt' . I want to remove the ' characters from the beginning and the end so that the my new variable becomes /example/file.txt . How can I do it in a script? I know this is a fairly easy question, but i wasn't able to implement it. (3 Replies)
Discussion started by: sertansenturk
3 Replies

8. Shell Programming and Scripting

Removing leading zeros from a variable

How do I remove or add leading zeroa from a variable. To make variable 10 characters long when adding zeros. (6 Replies)
Discussion started by: toshidas2000
6 Replies

9. UNIX for Advanced & Expert Users

how to unset the readonly variable

Hi All, May be this is a very simple question... $ b=8 $ readonly b $ echo $b 8 $ b=90 -bash: b: readonly variable $ 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 Replies)
Discussion started by: Nidhi2177
2 Replies
Login or Register to Ask a Question