Answers for "bash if"

23

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
Posted by: Guest on February-21-2020
7

if and if bash

if [ "${STATUS}" != 200 ] && [ "${STRING}" != "${VALUE}" ]; then
Posted by: Guest on May-23-2020
2

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
Posted by: Guest on September-14-2020
4

bash else if

if [ "$animal" == "penguin" ]; then
  echo "Hmmmmmm fish... Tux happy!"
elif [ "$animal" == "dolphin" ]; then
  echo "Pweetpeettreetppeterdepweet!"
else
  echo "*prrrrrrrt*"
fi

if TEST-COMMANDS; then
  CONSEQUENT-COMMANDS;
elif MORE-TEST-COMMANDS; then
  MORE-CONSEQUENT-COMMANDS;
else
  ALTERNATE-CONSEQUENT-COMMANDS;
fi
Posted by: Guest on November-12-2020
1

ash if statment

if [ "$USER" == "Adam" ]
then
	echo "User is Adam"
else
	echo "User is not Adam"
fi
Posted by: Guest on July-27-2020
0

bash if

#!/bin/bash
# your code goes here
echo "if double helix, type - dh " 
echo "single strand, type - ss"
read htype # this is catching input
echo Structure is $htype ;


if [[ $htype == dh ]];
then
     echo "##dublex#####"
else
    echo "#####single#####"
fi
Posted by: Guest on August-20-2021

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language