shanenin Posted April 24, 2005 Report Share Posted April 24, 2005 Is ther a way to show(list) all set and/or exported varibles in a bash shell?edit added later//I have a substitution question. Lets say I do this shane@mainbox shane $ DATE=${one:-two}shane@mainbox shane $ echo $DATEtwoHow would I get it to echo the value one? Quote Link to post Share on other sites
iccaros Posted April 24, 2005 Report Share Posted April 24, 2005 I think you want to do arrays.. (bash does one dimention arryas)here is a quick bash arraybash-2.05b$ cat test#!/bin/bashDATE[1]=oneDATE[2]=twoecho ${DATE[1]}bash-2.05b$ you could also do this#!/bin/bashecho" input an answer"read inpecho "input another answer"read inp2DATE[1]=$inpDATE[2]=$inp2echo ${DATE[1]}echo ${DATE[2]} Quote Link to post Share on other sites
jcl Posted April 24, 2005 Report Share Posted April 24, 2005 (edited) Is ther a way to show(list) all set and/or exported varibles in a bash shell?$ setwill print all shell variables, including those not exported.$ printenvor$ envwill 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 shane@mainbox shane $ DATE=${one:-two}shane@mainbox shane $ echo $DATEtwoHow would I get it to echo the value one?$ echo oneIn the form ${one:-two}, 'one' is the name of a variable, so the value won't be 'one' unless you happen to have$ one=onesomewhere. Edited April 24, 2005 by jcl Quote Link to post Share on other sites
shanenin Posted April 24, 2005 Author Report Share Posted April 24, 2005 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 doingDATE=${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. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.