小编shi*_*lch的帖子

用于在文件的每一行上执行命令的 Shell 脚本,其中包含空格分隔的字段

我正在尝试编写一个 shell 脚本,该脚本逐行读取文件并执行命令,其参数取自每行的空格分隔字段。

更准确地说,我需要使用 wget 从第二列中给出的 URL 下载一个文件到第一列中给出的路径。但我不知道如何加载此文件并获取脚本中的值。

文件.txt

file-18.log https://example.com/temp/file-1.log
file-19.log https://example.com/temp/file-2.log
file-20.log https://example.com/temp/file-3.log
file-21.log https://example.com/temp/file-4.log
file-22.log https://example.com/temp/file-5.log
file-23.pdf https://example.com/temp/file-6.pdf
Run Code Online (Sandbox Code Playgroud)

期望的输出是

wget url[1] -o url[0]

wget https://example.com/temp/file-1.log -o file-18.log
wget https://example.com/temp/file-2.log -o file-19.log
...
...
wget https://example.com/temp/file-6.pdf -o file-23.pdf
Run Code Online (Sandbox Code Playgroud)

unix arrays bash shell sh

0
推荐指数
1
解决办法
209
查看次数

标签 统计

arrays ×1

bash ×1

sh ×1

shell ×1

unix ×1