Sponsored By

Sign in to follow this  
shanenin

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
#!/bin/bash
DATE[1]=one
DATE[2]=two
echo ${DATE[1]}
bash-2.05b$    

you could also do this

#!/bin/bash
echo" input an answer"
read inp
echo "input another answer"
read inp2
DATE[1]=$inp
DATE[2]=$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

or

$ 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
two

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

somewhere.

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

DATE=${one:-three}

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this