How do i write this in sh/bash
Javascript/php:
This is the closest i can get without breaking it:Code:if ( 1 == 1 && ( 1==2 || 2==2 ) ) { }
Code:if [ 1 -eq 1 ] && [ 1 -eq 2 ] || [ 2 -eq 2 ];then fi
How do i write this in sh/bash
Javascript/php:
This is the closest i can get without breaking it:Code:if ( 1 == 1 && ( 1==2 || 2==2 ) ) { }
Code:if [ 1 -eq 1 ] && [ 1 -eq 2 ] || [ 2 -eq 2 ];then fi
Last edited by pqwoerituytrueiwoq; April 29th, 2013 at 03:51 PM. Reason: Solved
Laptop: ASUS A54C-NB91 (Storage: WD3200BEKT + MKNSSDCR60GB-DX); Desktop: Custom Build - Images included; rPi Server
Putting your Networked Printer's scanner software to shame PHP Scanner Server
I frequently edit my post when I have the last post
Edit: Forget it, it's all wrong. The following posts explain why.. trying variations, may post corrected one later..
works for me.Code:if [[ 1 -eq 1 && 1 -eq 2 || 2 -eq 2 ]];then fi
For example :
..change the declared values or test values and see the difference. It works as -Code:a=2; b=3; c=4; if [[ $a -eq 2 && $b -eq 2 || $c -eq 4 ]]; then echo yes; fi
IF (condition 1) AND (condition2 OR condition3), THEN go ahead..
Last edited by varunendra; April 29th, 2013 at 11:30 AM. Reason: Forgot $ in variable calls, Thanks to schragge for the heads up!
There's a subtle difference between &&/|| and -a/-o in that the former short-curcuit, but the latter don't. See compound comparison in ABS.
In this particular case, I'd use arithmetic evaluation
Also, using of parentheses to explicitly group subexpressions is allowed inside double-brackets and arithmetic expressions.Code:((1==1 && 1==2 || 2==2))
Edit || has lower precedence than &&, so parentheses are needed. See spjackson's explanation below.
Last edited by schragge; April 29th, 2013 at 12:00 PM.
The truth table for the original Javascript/php is:
However both of these suggestions:Code:TTT==>T TTF==>T TFT==>T TFF==>F FTT==>F FTF==>F FFT==>F FFF==>F
have the truth tableCode:if [[ 1 -eq 1 && 1 -eq 2 || 2 -eq 2 ]];then ((1==1 && 1==2 || 2==2))
i.e. different in 2 cases.Code:TTT==>T TTF==>T TFT==>T TFF==>F FTT==>T FTF==>F FFT==>T FFF==>F
Just as in the original, you need a bracket;
Code:if [[ 1 -eq 1 && ( 1 -eq 2 || 2 -eq 2 ) ]];then ((1==1 && (1==2 || 2==2)))
Thanks everyone
this is where i needed it
Laptop: ASUS A54C-NB91 (Storage: WD3200BEKT + MKNSSDCR60GB-DX); Desktop: Custom Build - Images included; rPi Server
Putting your Networked Printer's scanner software to shame PHP Scanner Server
I frequently edit my post when I have the last post
Two things about your script.
1. It downloads kernel-related packages to current directory and then counts files to check if they were successfully downloaded. What if there already were previously downloaded older kernel packages in the folder?
2. This
probably could be replaced withCode:if [ "`uname -m`" == "x86_64" ];then arch="amd64" else arch="i386" fi
and thisCode:arch=`dpkg --print-architecture`
withCode:[ $(ls /boot | grep $VER_A | wc -l) -gt 3 ]
Code:[[ -d /lib/modules/$VER_A ]]
Last edited by schragge; April 29th, 2013 at 07:56 PM.
If there are files present it will ask you if you want to delete them, if you say no wget will not replace them and will get the other files
edit:
opps now what you meant, thanks
https://github.com/GM-Script-Writer-...criptGenerator
Last edited by pqwoerituytrueiwoq; April 29th, 2013 at 08:22 PM.
Laptop: ASUS A54C-NB91 (Storage: WD3200BEKT + MKNSSDCR60GB-DX); Desktop: Custom Build - Images included; rPi Server
Putting your Networked Printer's scanner software to shame PHP Scanner Server
I frequently edit my post when I have the last post
Bookmarks