从文本文件中读取命令并将其传递到 Shell 中的脚本

Reading commands from text file and passing it into Script in Shell

我有一个 file.txt 其输出是

declare -a Pool=("Minland" "Tucson" "Vancouver")
declare -a Library=("lib1" "lib2" "lib3")
declare -a Name=("Guru" "Albert" "Jeff")
declare -a Email=("guru@abc.com,Narendra@abc.com" "abc@def.com" "ghi@abc.com")
declare -a Subject=("   Finland Media Rotation" "       Tucson Media Rotation" "        Vancouver Media Rotation")

我想将这些输出用作我的其他文件的命令。 以下是我的努力。

cat Hello.txt | xargs -d $'\n' sh -c sh Media.sh

它没有给出任何输出。

然后我试过的替代方法是像下面那样附加,但我知道这不是正确的方法。

cat file.txt Media.sh > out.sh
chmod +x out.sh
sh out.sh

所以,请帮我找出最好的选择。

您可以将 file.txt 文件的内容导入到脚本 Media.sh 中,并将下一条指令作为 Media.sh 文件的第一条指令:

. file.txt