linux command : if then fi
Hi,
it's just for a newbie question: how to convert this basic code in sh script code of linux ? Basic code: Code:
if ( "$HOSTNAME" = "orion" and "$tmpvariable" = "copy" ) then Linux sh code: Code:
#!/bin/sh |
That script works like a charm. You just need to make sure that your variables are exported.
export tmpvariable also assuming that you've set execute permissions on the script chmod +x <scriptname> best of luck! |
Works here ... maybe the variables haven't been exported properly?
Cheers, Tink P.S.: Heh - beat by a couple of seconds... |
That should work!
Anyway, you may want to try this: Code:
if [ "$HOSTNAME" == "orion" ] && [ "$tmpvariable" == "copy" ]; then |
Quote:
I have two questions. In my script, I should then add export: Code:
#!/bin/sh I dont really know why the export is very necessary yet. Actually why is it needed in such example ? :scratch: I just tried thsi: Quote:
and my second question is : Code:
[ "$HOSTNAME" == "orion" ] Code:
if [ "$HOSTNAME" = "orion" ] Which form is better to be used with = or == ? What's the difference ? this one : Quote:
and this alternate one: Quote:
non working one: Quote:
That was very interesting !! Thank you !! |
Quote:
mention of the variable being defined; and if it's supposed to be picked up from the environment it has to be exported. Quote:
Quote:
Cheers, Tink |
Ahhhh !! I understand !
Code:
#!/bin/sh Code:
#!/bin/sh I found why the one there is not working: Because only of the space too close : Quote:
that's very quick to make a mistake. I think even before == we should add space char. and working too : Code:
#!/bin/sh I learned a lot ! |
and sometimes we can see that there is [[ ]] double
what could be the deep purpose or use with this .. ? I tried but had some troubles (nothg was working )... via : if [[ "$HOSTNAME" == "orion" ]] ; then bla bla Quote:
Quote:
Also, Quote:
it's kind of like a simple if ... then ...fi Quote:
|
I don't have time for a good answer. Meanwhile, just one tip: don't forget the spaces around [ and ].
Yves. |
Here's a bit about -a vs && :
http://www.dartmouth.edu/~rc/classes...ests2.html#top See also here for [ ] vs [[ ]] http://www.tldp.org/LDP/abs/html/tes...ml#DBLBRACKETS |
Quote:
(I have to debug it now ... :-) :-) ) (errors errors...) To be continued Greetings ! |
All times are GMT -5. The time now is 09:29 AM. |