What is this Bash example trying to convey?
Code:
parameter expansion unset var var="" var="gnu" |
(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 Is this ok? |
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.
|
Unset essentially deletes the variable.
var="" might be used as an initialization, or to clear out the contents of a variable without fully deleting it with unset. |
Quote:
|
THREAD SOLVED! Thanks Everyone.
|
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? |
"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". |
After reading more on those parameter expansion options in man bash, and looking at examples i'm starting to understand.. Ok thanks man!
|
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! |
Quote:
|
Quote:
|
I got to wondering what's the difference between - and ? because the top two lines and the bottom two lines seem to have identical function.
So I ran "man bash" and searched for :- (by typing /:-) and found that they are almost identical but for two differences.
Code:
$ unset x |
All times are GMT -5. The time now is 11:07 PM. |