locale variables

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
ckonn
Level 3
Level 3
Posts: 180
Joined: Wed Oct 01, 2014 7:03 pm

locale variables

Post by ckonn »

hello,

how the user can get a list of a variable/s created by himself ( different from those in env-list )
and how could he delete it/them?

thank you in advance
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
Flemur
Level 20
Level 20
Posts: 10096
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: locale variables

Post by Flemur »

To see your locale variables, just type

Code: Select all

locale
If you want to see which ones you set, look in ~/.bashrc and ~/.profile
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
ckonn
Level 3
Level 3
Posts: 180
Joined: Wed Oct 01, 2014 7:03 pm

Re: locale variables

Post by ckonn »

well, my question was not exactly how to see the values of the bash global built-in variables using 'locale' or 'env', but to remember myself how much and what exactly variables I have created.

I remember that some time ago while watching a video about bash I have created my own ... how to say it ... personal variables and set them to a certain values but now I can not remember the names of this variables, their values, and where they are stored.
User avatar
Pilosopong Tasyo
Level 6
Level 6
Posts: 1432
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: locale variables

Post by Pilosopong Tasyo »

( set -o posix ; set ) | less

Unfortunately, it will list *both* shell variables (the ones you define) as well as environment variables. You will have to weed out for yourself which is which.

How to list user-defined variables declared in a script? - read here

AFAIK and to simplify, shell variables only exist within the lifetime of a script or terminal session. Once the script exits, that variable gets deallocated. You can try this in an open terminal window. Define some variables, close the terminal window, re-open, and re-enter the above command. All your user-defined variables in the previous session no longer exist.
o Give a man a fish and he will eat for a day. Teach him how to fish and he will eat for a lifetime!
o If an issue has been fixed, please edit your first post and add the word [SOLVED].
ckonn
Level 3
Level 3
Posts: 180
Joined: Wed Oct 01, 2014 7:03 pm

Re: locale variables

Post by ckonn »

Pilosopong Tasyo wrote:( set -o posix ; set ) | less

... shell variables only exist within the lifetime of a script or terminal session. Once the script exits, that variable gets deallocated. You can try this in an open terminal window. Define some variables, close the terminal window, re-open, and re-enter the above command. All your user-defined variables in the previous session no longer exist.

thanks for the answer!

so. the situation with the user-defined variables ( udvar ) created in the interactive bash shell became clear. once the terminal is closed all udvars disappear.

but what about a udvar created in a bash script? if a user create a variable/s in a bash shell script/s is there a command that could list all udvars, and in which scripts exactly they are? or you just have to open a given script and see what udvars it contains?
User avatar
Pilosopong Tasyo
Level 6
Level 6
Posts: 1432
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: locale variables

Post by Pilosopong Tasyo »

ckonn wrote:but what about a udvar created in a bash script? if a user create a variable/s in a bash shell script/s is there a command that could list all udvars, and in which scripts exactly they are? or you just have to open a given script and see what udvars it contains?
The link I posted in my earlier reply appears to be the way to do it (unless if another member knows of an easier way, feel free to chime in). Problem is, you'll need to run the script (source scriptname) just to make a before-and-after comparison. Doing this may prove less optimal if you scripts need to run only when certain conditions are met.
o Give a man a fish and he will eat for a day. Teach him how to fish and he will eat for a lifetime!
o If an issue has been fixed, please edit your first post and add the word [SOLVED].
lmuserx4849

Re: locale variables

Post by lmuserx4849 »

Difference between env and declare -p variables:

Code: Select all

diff -y  <(env|cut -d "=" -f1 | sort)  <(declare -p | awk '{ print substr($3,1,match($3,"=|$")-1) }')
Locked

Return to “Scripts & Bash”