#!/bin/bash
Echo “Enter a number”
Read  $number
If [$number ] ; then 
Echo “Your number is divisible by 5”
Else
Echo “Your number is not divisible by 5”
fiคำสั่ง if [$ number] คือสิ่งที่ฉันไม่รู้วิธีตั้งค่า
#!/bin/bash
Echo “Enter a number”
Read  $number
If [$number ] ; then 
Echo “Your number is divisible by 5”
Else
Echo “Your number is not divisible by 5”
fiคำสั่ง if [$ number] คือสิ่งที่ฉันไม่รู้วิธีตั้งค่า
คำตอบ:
คุณสามารถใช้ไวยากรณ์ที่ง่ายกว่าใน Bash กว่าบางรายการที่แสดงที่นี่:
#!/bin/bash
read -p "Enter a number " number    # read can output the prompt for you.
if (( $number % 5 == 0 ))           # no need for brackets
then
    echo "Your number is divisible by 5"
else
    echo "Your number is not divisible by 5"
fiif (( 10#$number % 5 == 0 ))เพื่อบังคับ$numberให้ตีความเป็นฐาน 10 (แทนที่จะเป็นฐาน 8 / ฐานแปดโดยนัยจากศูนย์นำหน้า)
                    ไม่มีBCจำเป็นตราบเท่าที่มันของคณิตศาสตร์จำนวนเต็ม (คุณจะต้อง BC จุดแม้ว่าลอย): ในทุบตีที่(())ผู้ประกอบการทำงานเหมือนexpr
เป็นคนอื่นได้ชี้ให้เห็นการดำเนินการที่คุณต้องการคือแบบโมดูโล (%)
#!/bin/bash  
echo "Enter a number"
read number
if [ $(( $number % 5 )) -eq 0 ] ; then
   echo "Your number is divisible by 5"
else
   echo "Your number is not divisible by 5"
fiวิธีการเกี่ยวกับการใช้bcคำสั่ง:
!/usr/bin/bash
echo “Enter a number”
read number
echo “Enter divisor”
read divisor
remainder=`echo "${number}%${divisor}" | bc`
echo "Remainder: $remainder"
if [ "$remainder" == "0" ] ; then
        echo “Your number is divisible by $divisor”
else
        echo “Your number is not divisible by $divisor”
fiexpr $number % $divisor
                    bcมีความเชี่ยวชาญในการคำนวณมันสามารถจัดการสิ่งต่าง ๆ เช่น 33.3% 11.1 ซึ่งexprน่าจะทำให้หายใจไม่ออก
                    คำตอบ nagul เป็นดี แต่เพียง FYI การดำเนินการที่คุณต้องการคือโมดูลัส (หรือโมดูโล) %และผู้ประกอบการโดยทั่วไป
ฉันได้ทำมันในวิธีที่แตกต่าง ตรวจสอบว่ามันเหมาะกับคุณ 
ตัวอย่างที่ 1:
num=11;
[ `echo $num/3*3 | bc` -eq $num ] && echo "is divisible" || echo "not divisible"
Output : not divisibleตัวอย่างที่ 2:
num=12;
[ `echo $num/3*3 | bc` -eq $num ] && echo "is divisible" || echo "not divisible"
Output : is divisibleตรรกะง่ายๆ
12/3 = 4 
4 * 3 = 12 -> หมายเลขเดียวกัน  
11/3 = 3 
3 * 3 = 9 -> ไม่เหมือนกัน
เพียงแค่ในความสนใจของไวยากรณ์เป็นกลางและการแก้ไขอคติโน้ตมัดโจ่งแจ้งทั่วชิ้นส่วนเหล่านี้เราได้มีการปรับเปลี่ยนวิธีการแก้ปัญหาของ nagul dcกับการใช้งาน
!/usr/bin/bash
echo “Enter a number”
read number
echo “Enter divisor”
read divisor
remainder=$(echo "${number} ${divisor}%p" | dc)
echo "Remainder: $remainder"
if [ "$remainder" == "0" ]
then
        echo “Your number is divisible by $divisor”
else
        echo “Your number is not divisible by $divisor”
fidcติดตั้ง
                    คุณสามารถใช้exprเช่น:
#!/bin/sh
echo -n "Enter a number: "
read number
if [ `expr $number % 5` -eq 0 ]
then
    echo "Your number is divisible by 5"
else
    echo "Your number is not divisible by 5"
fi