Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

bash single bracket and double square bracket

more likey [] is for math orerations 
[[ ]] for pattern matching, 


eg 1 ###########
eg: 
if [ $marks -ge 80 ];
then
	do something
fi


####################
eg2 :

#!/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

but you can use both, use [[ ]] will be safe,

Note that [[ is actually a command/program that returns either 0 (true) or 1 (false). Any program that obeys the same logic (like all base utils, such as grep(1) or ping(1)) can be used as condition, see examples.

[[ -z STRING ]]	Empty string
[[ -n STRING ]]	Not empty string
[[ STRING == STRING ]]	Equal
[[ STRING != STRING ]]	Not Equal
[[ NUM -eq NUM ]]	Equal
[[ NUM -ne NUM ]]	Not equal
[[ NUM -lt NUM ]]	Less than
[[ NUM -le NUM ]]	Less than or equal
[[ NUM -gt NUM ]]	Greater than
[[ NUM -ge NUM ]]	Greater than or equal
[[ STRING =~ STRING ]]	Regexp
(( NUM < NUM ))	Numeric conditions
More conditions
[[ -o noclobber ]]	If OPTIONNAME is enabled
[[ ! EXPR ]]	Not
[[ X && Y ]]	And
[[ X || Y ]]	Or
Source by devhints.io #
 
PREVIOUS NEXT
Tagged: #bash #single #bracket #double #square #bracket
ADD COMMENT
Topic
Name
4+2 =