如何在unix上使用shell脚本替换for…in循环中文件路径的一部分?

如何在unix上使用shell脚本替换for…in循环中文件路径的一部分?,unix,for-in-loop,Unix,For In Loop,我需要帮助。我完全被这件事缠住了。我(递归地)遍历目录中的所有文件并打印文件列表。比如: # srcDir="input received from command line" # tgtDir="input received from command line" for listItem in `find ${srcDir}` do if [[ -f ${listItem} ]] then echo ${listItem} # **** what to put

我需要帮助。我完全被这件事缠住了。我(递归地)遍历目录中的所有文件并打印文件列表。比如:

# srcDir="input received from command line"
# tgtDir="input received from command line"

for listItem in `find ${srcDir}`
do
    if [[ -f ${listItem} ]]
    then
        echo ${listItem} # **** what to put here ****
    fi
done
# let's assume that srcDir="/home/user"
# and tgtDir="/tmp/guest"
# srcDir has the following structure
file1.txt
dir1_1/file1a.txt
dir1_1/file1b.txt

# so the actual output of the script will be
/home/user/file1.txt
/home/user/dir1_1/file1a.txt
/home/user/dir1_1/file1b.txt

# but I want it to print as
/tmp/guest/file1.txt
/tmp/guest/dir1_1/file1a.txt
/tmp/guest/dir1_1/file1b.txt
打印列表时,我想替换文件从srcDir到tgtDir的路径。比如:

# srcDir="input received from command line"
# tgtDir="input received from command line"

for listItem in `find ${srcDir}`
do
    if [[ -f ${listItem} ]]
    then
        echo ${listItem} # **** what to put here ****
    fi
done
# let's assume that srcDir="/home/user"
# and tgtDir="/tmp/guest"
# srcDir has the following structure
file1.txt
dir1_1/file1a.txt
dir1_1/file1b.txt

# so the actual output of the script will be
/home/user/file1.txt
/home/user/dir1_1/file1a.txt
/home/user/dir1_1/file1b.txt

# but I want it to print as
/tmp/guest/file1.txt
/tmp/guest/dir1_1/file1a.txt
/tmp/guest/dir1_1/file1b.txt
我希望你明白了。请给出建议。

看起来像是以下职位的工作: