How do you think conditional statements are implemented in a shell?
> tar -xjf myarchive.tar.bz2 && gv content.ps
...would work as little as any loop condition, pipeline etc. if it weren't for values returned from the program.
In the zsh, try
> false
> echo $?
> echo $?
...which will result in the output 1 and then 0, since false returns 1, and echo (if it doesn't fail, which is unlikely) returns 0.
A variable is stored somewhere in the computer memory, an expression is just evaluated:
1 2 3
int v = 5; // 'v' is a variable with 5 as value
3+2; // '3+2' is an expression (with 5 as result) but it is not stored
v = 3+2; // '3+2' is evaluated and the result is assigned to be the value for 'v'
Another question. I guess these will just keep on coming. :(
I wrote this code:
1 2 3 4 5 6 7 8 9 10
int Hat = 56;
Hat += 2;
cout << Hat;
int Rat;
cout << "Enter Rat";
cin >> Rat;
Hat = Rat + 2;
cout << Hat;
Now, if I entered "2" for Rat, then the final equation for Hat should be:
56 = 2 + 2 right?
But I don't get this answer. All I get is the value I entered for Rat + 2. Why won't the computer add that answer to 56? Instead all it does is overwrite the original value of Hat, which in this case was 56, and just put in a new value, which would be Rat + 2. Why does it do this? And how can I get past it?
If you do something like this: Hat = 2; you are setting the value of Hat to 2.
If you do something like this Hat += 2; you are adding 2 to the previous value of Hat.
So, in Hat = Rat + 2; you are setting Hat to Rat+2
So basically, the original value of Hat gets overwritten? Because in the beginning of the code, I initialized Hat to 56, and then added 2 to it. But later on, I wrote "Hat = Rat + 2".
What I don't understand is, why doesn't the computer store the original value that I put for Hat? Why does it get overwritten during the last part of the code?