xargs 我已经有完整的命令集

发布于 2024-08-24 17:15:49 字数 165 浏览 2 评论 0原文

我有一个这样的文件。

rm a.txt
mkdir foo
cp a.doc docs

我习惯了 xargs 但以下命令没有执行任何操作。

cat commands.txt | xargs -l1

I have a file like this.

rm a.txt
mkdir foo
cp a.doc docs

I am used to xargs but following command is not doing anything.

cat commands.txt | xargs -l1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

兮颜 2024-08-31 17:15:49

你做错了!如果你的文件全是shell命令,就把它当成shell脚本。

#!/bin/bash
rm a.txt
mkdir foo
cp a.doc docs

然后在命令行上,chmod u+xcommands.txt

./commands.txt

shell脚本的“事实上”命名约定以扩展名.sh结尾,尽管它可以是任何东西。所以尝试将你的脚本命名为“.sh”扩展名

you are doing it wrong! if your file is all shell commands, treat it as a shell script.

#!/bin/bash
rm a.txt
mkdir foo
cp a.doc docs

then on command line , chmod u+x commands.txt

./commands.txt

the "defacto" naming convention for shell script ends with extension .sh, although it can be anything. So try to name your script as ".sh" extension

故人的歌 2024-08-31 17:15:49

呃:

$ mv 命令.txt 命令.sh

$ chmod +x 命令.sh

$ ./command.sh

Erm :

$ mv commands.txt commands.sh

$ chmod +x command.sh

$ ./command.sh

我不是你的备胎 2024-08-31 17:15:49

如果您不需要使其可执行,请在当前 shell 中获取它:

bash/ksh/...: 。命令.txt

csh/...: 源命令.txt

If you don't need to make it executable, source it in your current shell:

bash/ksh/...: . commands.txt

csh/...: source commands.txt

知你几分 2024-08-31 17:15:49

如果您的命令不在文件中,而是程序的输出,您可以使用 GNU Parallel http:// /www.gnu.org/software/parallel/

cat commands.txt | parallel -j1

如果命令可以并行运行(即不依赖于彼此来完成),您甚至可以这样做:

cat commands.txt | parallel

If you commands are not in a file but the output from a program you may do use GNU Parallel http://www.gnu.org/software/parallel/:

cat commands.txt | parallel -j1

If the commands can be run in parallel (i.e. do not depend on eachother to complete) you can even do:

cat commands.txt | parallel
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文