locale variables

Forum rules
Before you post please read how to get help
ckonn
Level 2
Level 2
Posts: 50
Joined: Wed Oct 01, 2014 7:03 pm

locale variables

Postby ckonn » Wed Apr 19, 2017 1:29 pm

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
linux mint 17.3 mate

User avatar
Flemur
Level 13
Level 13
Posts: 4631
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: locale variables

Postby Flemur » Wed Apr 19, 2017 2:50 pm

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
Xubuntu 17.10/fluxbox/pulse-less
Mint 18.2 Xfce/fluxbox/pulse-less
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?

ckonn
Level 2
Level 2
Posts: 50
Joined: Wed Oct 01, 2014 7:03 pm

Re: locale variables

Postby ckonn » Thu Apr 20, 2017 2:43 am

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.
linux mint 17.3 mate

User avatar
Pilosopong Tasyo
Level 6
Level 6
Posts: 1423
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: locale variables

Postby Pilosopong Tasyo » Thu Apr 20, 2017 4:40 am

( 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.
Image
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 2
Level 2
Posts: 50
Joined: Wed Oct 01, 2014 7:03 pm

Re: locale variables

Postby ckonn » Thu Apr 20, 2017 6:54 am

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?
linux mint 17.3 mate

User avatar
Pilosopong Tasyo
Level 6
Level 6
Posts: 1423
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: locale variables

Postby Pilosopong Tasyo » Thu Apr 20, 2017 8:21 am

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.
Image
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
Level 4
Level 4
Posts: 489
Joined: Wed Dec 17, 2014 2:55 am

Re: locale variables

Postby lmuserx4849 » Wed Apr 26, 2017 12:03 am

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) }')


Return to “Scripts & Bash”