[Linux] Shell Script "==" and "=~"

# "=="
set text0 = "World"
set text1 = "World"
set text2 = "Hello World"
set text3 = "Hello World !!"

if( $text2 == $text3) then
 echo "$text2 == $text3"
else
 echo "$text2 != $text3"
endif

if( $text0 == text1) then
 echo "$text0 == $text1"
else
 echo "$text0 != $text1"
endif
-------------------------------------------
output:
Hello World !! != Hello World !!
World == World
# "=~"
set text1 = "World"
set text2 = "Hello World"
set text3 = "Hello World !!"

if( $text3 =~ $text2) then
 echo "$text2 is $text3 Substring"
else
 echo "$text2 not $text3 Substring"
endif

if( $text2 =~ text1) then
 echo "$text1 is $text2 Substring"
else
 echo "$text1 not $text2 Substring"
endif
-------------------------------------------
output:
Hello World is Hello World !! Substring
World is Hello World Substring
By Hao★

留言

熱門文章

[C#] 將DataTable轉換成Html格式表格

[MS SQL] 查詢所有Procedure