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

if else statement example in shell script

if [ ... ]
then
  # if-code
else
  # else-code
fi
Comment

if and if bash

if [ "${STATUS}" != 200 ] && [ "${STRING}" != "${VALUE}" ]; then
Comment

if statement in shell script

  if [ "$result" == "1" ]
    then 
      echo "test" >> /home/samurai/test.txt
    fi
    

    
    if [[ "$result" -eq "1" ]]
    then 
      echo "test" >> /home/samurai/test.txt
    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

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 :: cd to root directory windows 
Shell :: find file linux 
Shell :: remove yum package 
Shell :: linux remove link 
Shell :: linux list all system groups in order 
Shell :: composer add git repository 
Shell :: start arangodb 
Shell :: regex match + n lines 
Shell :: flutter pubspec install 
Shell :: powershell t admin 
Shell :: install node package manager 
Shell :: bash calculate sum 
Shell :: gui for ubuntu server 
Shell :: wp cli plugin install 
Shell :: raspberry pi default username 
Shell :: bash check if command is available 
Shell :: dev/mapper/ubuntu--vg-ubuntu--lv 
Shell :: cant-push-to-github-because-of-large-file-which-i-already-deleted 
Shell :: Bell char 
Shell :: docker start container 
Shell :: bash call another script relative to current script 
Shell :: how to use compress zip cli linux 
Shell :: github checkout branch 
Shell :: install astropy anaconda 
Shell :: what is github 
Shell :: can i do git push to heroku branch which isnt a master or main 
Shell :: bash count occurrences of string in array 
Shell :: bash arrays 
Shell :: svelte typescript 
Shell :: wp cli change tagline 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =