
内容file.txt
:
apple
mango
orange
我的脚本应该读取apple
并创建一个零字节文件apple.txt
然后mango.txt
文件。
有人可以帮忙吗?
答案1
使用 GNU xargs
:
sed 's/$/.txt/' < file | xargs -rd '\n' touch --
答案2
while read filename; do > ${filename}.txt; done < file.txt
答案3
类似的东西可以完成这项工作
while read a
do
touch "${a}.txt"
done <file.txt
但是,如果您在文件行中包含空格或特殊符号,则可能会出现问题。
为了避免单词/文件中出现反斜杠问题,您可以使用以下代码:
while read -r a
do
touch "${a}.txt"
done <file.txt