ฉันมีโปรแกรมขนาดเล็กซึ่งมีโครงสร้างโฟลเดอร์ต่อไปนี้:
- main.sh
- lib/
- clean.sh
- get.sh
- index.sh
- test.sh
main.shแต่ละไฟล์ที่มีฟังก์ชั่นเดียวที่ผมใช้ใน
main.sh:
source lib/*
get_products
clean_products
make_index
test_index
ในสองฟังก์ชันแรกด้านบนทำงานได้ แต่ฟังก์ชันที่สองไม่ทำงาน
แต่ถ้าฉันแทนที่source lib/*ด้วย:
source lib/get.sh
source lib/clean.sh
source lib/index.sh
source lib/test.sh
ทุกอย่างทำงานตามที่คาดไว้
ใครรู้ว่าทำไมsource lib/*ไม่ทำงานตามที่คาดไว้
/etc/bashrcว่ามันใช้forลูปในการจัดการ/etc/profile.d/*.shอย่างไร หากคุณเชื่อว่าเนื้อหาของlib/มันสามารถลดลงหนึ่งซับ:for i in lib/*.sh; do . "$i"; done