shell 程序问题,在其他 sh 脚本中重复执行 sh 脚本

shell program issues, exec sh script repeatedly in other sh script

我的目的是用输入的文件重复执行a.sh。 但是在运行run.sh之后,我们可以看到a.sh只执行了一次!

the code is as below:
        

 run.sh:
            #!/bin/bash
            echo "$$"
            for fname in "../hostchng/*"
            do
              echo $fname
              source ./a.sh $fname
            done
            
            
        a.sh:
            echo "test   $$"

* 在被引用时不会扩展为一个 glob。所以

for fname in "../hostchng/*"; do ... done

fname 设置为文字字符串 ../hostchng/* 并恰好运行一次循环。如果要遍历目录中的名称,请删除引号:

for fname in ../hostchng/*; do ... done