for i in $(ls);do
    if [ $i = '*.java' ];then
        echo "I do something with the file $i"
    fi
done
ฉันต้องการวนซ้ำแต่ละไฟล์ในโฟลเดอร์ปัจจุบันและตรวจสอบว่าตรงกับนามสกุลที่ระบุหรือไม่ โค้ดด้านบนใช้ไม่ได้คุณรู้ไหมว่าทำไม?
$iกับสตริงตัวอักษร "* .java"; ไม่ได้ทำการขยายรูปแบบที่นี่
                if [[ $i == *.java ]]; then.. (สังเกต double [[]] s และ unquoted * .java)
                ls - ยอมรับคำตอบของ @ chepner
                
for i in $(ls *.java); do echo "do something with file $i"; done?