: '
Cách viết nhiều dòng comment.
Cách viết nhiều dòng comment.
Cách viết nhiều dòng comment.
'
NAME="Tuan"
AGE=18
echo "Tôi tên là $name, Năm nay tôi $AGE tuổi."
echo "Bạn đang công việc gì ?"
read -r job
echo "$job là một công việc tuyệt vời"
echo "Nhập vào X:"
read -r X
echo "Nhập vào Y"
read -r Y
((sum=X+Y))
echo "Sum: $sum"
echo "Nhập vào số may mắn của bạn"
read -r n
if [ "$n" -eq 101 ]; then
echo "Chúc mừng bạn đã đạt giải nhất"
elif [ "$n" -eq 510 ]; then
echo "Bạn đạt giải nhì"
elif [ "$n" -eq 999 ]; then
echo "Bạn đạt giải ba"
else
echo "Chúc bạn may mắn lần sau"
fi
echo "Nhập vào số may mắn của bạn"
read -r n
case $n in
101) echo echo "Chúc mừng bạn đã đạt giải nhất" ;;
510) echo "Bạn đạt giải nhì" ;;
999) echo "Bạn đạt giải ba" ;;
*) echo "Chúc bạn may mắn lần sau" ;;
esac
function F1() {
echo 'I like bash programming'
}
F1
Dien_Tich() {
area=$(($1 * $2))
echo "Diện Tích là : $area m2"
}
Dien_Tich 10 20
function greeting() {
str="Hello, $name"
echo "$str"
}
echo "Enter your name"
read -r name
val=$(greeting)
echo "Return value of the function is $val"
valid=true
count=1
while [ $valid ]; do
echo $count
if [ $count -eq 5 ]; then
break
fi
((count++))
done
for (( counter=10; counter>0; counter-- )); do
echo -n "$counter "
done
printf "\n"
echo "Enter directory name"
read -r newdir
mkdir "$newdir"
echo "Enter directory name"
read -r ndir
if [ -d "$ndir" ]; then
echo "Directory exist"
else
mkdir "$ndir"
echo "Directory created"
fi
echo "Enter file name"
read -r newfile
touch "$newfile"
filename=$1
if [ -f "$filename" ]; then
echo "File exists"
else
echo "File does not exist"
fi
file='book.txt'
while read line; do
echo "$line"
done < $file
echo "Before appending the file"
cat book.txt
echo "Learning Laravel 5">> book.txt
echo "After appending the file"
cat book.txt
echo "Enter filename to remove"
read -r fn
rm -i "$fn"
Tạo file test.sh và lưu trữ đoạn code dưới vào file
#!/bin/bash
echo "Total arguments : $#"
echo "1st Argument = $1"
echo "2nd argument = $2"
terminal exec
$ bash test.sh Linux Hint
Tạo file test2.sh và lưu trữ đoạn code dưới vào file
#!/bin/bash
for arg in "$@"; do
index=$(echo $arg | cut -f1 -d=)
val=$(echo $arg | cut -f2 -d=)
case $index in
X) x=$val;;
Y) y=$val;;
*)
esac
done
((result=x+y))
echo "X+Y=$result"
terminal exec
$ bash command_line.sh X=20 Y=50
FILE_ENV="./.env"
if [ -f "$FILE_ENV" ]; then
. "$FILE_ENV"
fi
echo "$ENV"
Year=$(date +%Y)
Month=$(date +%m)
Day=$(date +%d)
Hour=$(date +%H)
Minute=$(date +%M)
Second=$(date +%S)
echo $(date)
echo "Current Date is: $Day-$Month-$Year"
echo "Current Time is: $Hour:$Minute:$Second"
echo "Wait for 5 seconds"
sleep 5
echo "Completed"
Recipient="admin@example.com"
Subject="Greeting"
Message="Welcome to our site"
mail -s $Subject $Recipient <<< "$Message"