fbpx
Categories
Linux Server tips

Server Tips

ชุดคำสั่งใช้งานต่าง ๆ ที่จำเป็นสำหรับงานระบบเซิร์ฟเวอร์

Avatar photo

By OTTO

I'm a graphics design, 3d model, game apps developer. I'm very young programmer. Thank for everyone support me. งานและชีวิตของผม เริ่มต้นจากสิ่งที่ผมรัก ครอบครัวที่คอยสนับสนุนผมครับ

5 replies on “Server Tips”

รวมคำสั่งที่จำเป็นใน shell script สำหรับใช้ตัดสินใจ if else

Command Description
&& Logical AND
$0 Argument 0 i.e. the command that’s used to run the script
$1 First argument (change number to access further arguments)
-eq Equality check
-ne Inequality check
-lt Less Than
-le Less Than or Equal
-gt Greater Than
-ge Greater Than or Equal

ตรวจสอบข้อมูลว่าตรงการหรือไม่

#!/bin/bash
m=1
n=2

if [ $n -eq $m ]
then
echo “Both variables are the same”
else
echo “Both variables are different”
fi

เขียนคำสั่งตรวจสอบ มากว่าน้อยกวา

#!/bin/bash
a=2
b=7
if [ $a -ge $b ]
then
echo “The variable ‘a’ is greater than the variable ‘b’.”
else
echo “The variable ‘b’ is greater than the variable ‘a’.”
fi

เขียนคำสั่งคำนวณค่าโดยใช้ if else

#!/bin/bash
n=10
if [ $((n%2))==0 ]
then
echo “The number is even.”
else
echo “The number is odd.”
fi

#Shell Script ฝึกเขียน bash file สั่งงานระบบ

#!/bin/bash
echo “Enter password”
read pass
if [ $pass=”password” ]
then
echo “The password is correct.”
else
echo “The password is incorrect, try again.”
fi

Leave a Reply

Your email address will not be published. Required fields are marked *