<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <link rel="stylesheet" type="text/css" href="mystyle.css"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="keywords" content="if, unix, shell"> <meta name="author" content="Aleksandar Todorovic"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>if|if</title> </head> <body> <header> <div class="nav"> <ul> <li><a href="index.html">home</a></li> <li><a href="index_if.html">if</a> <ul> <li class="current"><a href="if.html"></a>if-fi</li> <li><a href="if-else.html"></a>if-else</li> <li><a href="elif.html"></a>if-elif</li> </ul> </li> <li><a href="loops_index.html">Loops</a> <ul> <li><a href="while.html"></a>while</li> <li><a href="for.html"></a>for</li> </ul> </li> </ul> </div> </header> <div class="syntax"> <h2>syntax of if</h2> <P>if [ expresion ] <br> then <br> statement to be executed if expresion is true <br> fi <br> </P> <div class="notice"> <h3>Important notice</h3> <ul> <li>if expression is a shell comand, then it will be <br> assumed true if it return 0 after execution</li> <li>If it is a boolean expression, then it would be true <br> if it returns true</li> <li>Space between braces and expression it's important because <br> no space produce a syntax error</li> <li>"fi"is "if backward</li> </ul> </div> <h2>Exemple</h2> <P>#!/bin/sh <br> var1=20 <br> var2=10 if[ var1==1var2 ] <br> then <br> echo "var1 is equal var2" <br> fi </div> <footer> <h4>Source</h4> <ul> <li>https://www.shellscript.sh/loops.html</li> <li>https://www.autistici.org/loa/shodan/corsounix.pdf</li> <li>https://www.guru4technoworld.wix.com</li> </ul> </footer> </body> </html>