Sign in to follow this  

Show All Set Variables

Recommended Posts

I think you want to do arrays.. (bash does one dimention arryas)

here is a quick bash array

bash-2.05b$ cat test
echo ${DATE[1]}

you could also do this

echo" input an answer"
read inp
echo "input another answer"
read inp2
echo ${DATE[1]}
echo ${DATE[2]}

Share this post

Link to post
Share on other sites
Is ther a way to show(list) all set and/or exported varibles in a bash shell?

$ set

will print all shell variables, including those not exported.

$ printenv


$ env

will print exported variables. The latter will also allow you to modify the environment before issuing a command.

I have a substitution question. Lets say I do this

[email protected] shane $ DATE=${one:-two}
[email protected] shane $ echo $DATE

How would I get it to echo the value one?

$ echo one


In the form ${one:-two}, 'one' is the name of a variable, so the value won't be 'one' unless you happen to have

$ one=one


Edited by jcl

Share this post

Link to post
Share on other sites

wow that set command is handy. Now I am able to kind of see what is happening.

I thought that $DATE would change depnding on what 'one' was set to. It does but 'one' has to be set before doing


I was setting 'one' after using the above command. Then It has no effect one the variable DATE.

So long as 'one' is not set before using DATE=${one:-three} three is substituted.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this