[SOLVED] What is this Bash example trying to convey?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
(I do not know where is it taken from)
We have now 3 columns with 3 different settings: var is unset, var is set, but the value is an empty string, var is equal to gnu.
we have 6 expressions on 6 lines and you can see how they evaluated using the 3 different var.
Code:
var is: unset empty gnu
${var-default} default — gnu
${var:-default} default default gnu
${var+alternate} — alternate alternate
${var:+alternate} — — alternate
${var?error} error — gnu
${var:?error} error error gnu
Thanks for replying pan64 that does clear some stuff up, but I just have two questions: is there ever a situation where you would put var="" in a script? I already know that var="gnu" maps gnu to the name var, but what's the point of having nothing mapped to var? And secondly, what does unset mean? I Googled unset but I couldn't find anything saying exactly what it was.
Last edited by justmy2cents; 06-16-2017 at 04:31 PM.
Actually what do you guys think alternate, default and error mean? In the columns.. Like what is it referring to?
Also is iam="cool" an expansion, or is ${cool} the expansion?
Last edited by justmy2cents; 06-16-2017 at 02:17 PM.
"default", "alternate", and "error" don't mean anything, that's just what they put in the expansion in the left column, you can replace them with any string.
iam="cool" is a variable assignment, you're setting the variable "iam" equal to the string "cool".
Others may disagree, but in my opinion man bash is a really an excellent resource!
It is long (i.e. complete) and some people seem to resist navigating around man pages, but time learning your way around man bash, and working through your own test cases is time very well spent indeed!
Others may disagree, but in my opinion man bash is a really an excellent resource!
It is long (i.e. complete) and some people seem to resist navigating around man pages, but time learning your way around man bash, and working through your own test cases is time very well spent indeed!
definitely I agree but only once you get an idea what you're looking at, and that usually requires (at least for me) a "more human" explanation.
definitely I agree but only once you get an idea what you're looking at, and that usually requires (at least for me) a "more human" explanation.
I used to say: man pages are really good, but only if you have forgotten something and need to check how it was really designed. But sometimes really hard to understand a tool just by reading its man page. bash is a really complex piece of software. If you have questions you can always ask here....
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.