Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

bash if statement

and - &&
or - ||

# and example
if [ -r $1 ] && [ -s $1 ]
then
echo This file is useful.
fi

# or example
if [ $USER == 'bob' ] || [ $USER == 'andy' ]
then
ls -alh
else
ls
fi
Comment

bash if

#!/bin/bash

foo="qux"
bar="qux"

if [ "$foo" = "$bar" ]; then
    echo "The strings are equal."
else
    echo "The strings aren't equal."
fi
Comment

bash if statement

Operator			Description
! EXPRESSION			The EXPRESSION is false.
-n STRING			The length of STRING is greater than zero.
-z STRING			The lengh of STRING is zero (ie it is empty).
STRING1 = STRING2		STRING1 is equal to STRING2
STRING1 != STRING2		STRING1 is not equal to STRING2
INTEGER1 -eq INTEGER2		INTEGER1 is numerically equal to INTEGER2
INTEGER1 -gt INTEGER2		INTEGER1 is numerically greater than INTEGER2
INTEGER1 -lt INTEGER2		INTEGER1 is numerically less than INTEGER2
-d FILE				FILE exists and is a directory.
-e FILE				FILE exists.
-r FILE				FILE exists and the read permission is granted.
-s FILE				FILE exists and it's size is greater than zero (ie. it is not empty).
-w FILE				FILE exists and the write permission is granted.
-x FILE				FILE exists and the execute permission is granted.
Comment

bash if

nome=tiago
## with SPACE between variable and comparation
if [ $nome == 'tiago' ] ;
then
    echo "hello Tiago"
fi
Comment

bash ifelse

# you can use it if you want but it isn't very accurate
# as of best practices and such 

for DB in $( sudo mysql -e 'show databases' -s --skip-column-names ) ; 
	do 
		if [ $DB == 'information_schema' ] || [ $DB == 'performance_schema' ]; 
        	then echo 'warning' ; 
        else 
        	echo "success $DB";
        fi 
        
    done
Comment

if statement bash

#!/bin/bash
# Basic if statement
if [ $1 -gt 100 ]
then
echo Hey that's a large number.
pwd
fi
Comment

Bash if statement

if first-test-commands; then
  consequent-commands;
[elif more-test-commands; then
  more-consequents;]
[else alternate-consequents;]
fi
Comment

PREVIOUS NEXT
Code Example
Shell :: cannot update paths and switch to branch at the same time 
Shell :: print variable in bash 
Shell :: git ls-files --others -i --exclude-standard 
Shell :: manjaro linux system information 
Shell :: how to change my default branch in git 
Shell :: awk split each character 
Shell :: apt install yarn 
Shell :: bash if file content equals 
Shell :: drf social auth 
Shell :: compare repositories github 
Shell :: how to install docker compose on windows 
Shell :: add ssh to github 
Shell :: install flutter in android studio 
Shell :: how to copy folder in linux 
Shell :: ssh current directory 
Shell :: bash tar list of files from folder 
Shell :: linux switch user 
Shell :: Remove a file from a Git repository without deleting it from the local 
Shell :: to take screenshot in ubuntu 
Shell :: pip install cookiecutter 
Shell :: view certificate openssl 
Shell :: install wordpress on centos 7 
Shell :: how to move to directories in command prompt 
Shell :: bash exit code 
Shell :: cmd run exe as service 
Shell :: docker copy folder to container 
Shell :: install node on fish shell 
Shell :: E: Unable to locate package libclang-cpp-dev 
Shell :: change dns in openvpn config 
Shell :: find the process ID of a running process bash 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =