Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 通过xargs管道传输时如何组合多个命令?_Bash_Shell_Xargs - Fatal编程技术网

Bash 通过xargs管道传输时如何组合多个命令?

Bash 通过xargs管道传输时如何组合多个命令?,bash,shell,xargs,Bash,Shell,Xargs,我有以下命令: !nohup fswatch-o~/Notes-e“\\.git.*”| xargs-n1-I{}sh~/auto_commit.sh>/dev/null 2>&1& 我想内联auto_commit.sh文件中的内容: cd ~/Notes git add -A git commit --allow-empty-message -am "" 有办法做到这一点吗?我最终得到的解决方案是: nohup fswatch -o ~/Notes -e "\\.git.*" | xargs

我有以下命令:

!nohup fswatch-o~/Notes-e“\\.git.*”| xargs-n1-I{}sh~/auto_commit.sh>/dev/null 2>&1&

我想内联
auto_commit.sh
文件中的内容:

cd ~/Notes
git add -A
git commit --allow-empty-message -am ""

有办法做到这一点吗?

我最终得到的解决方案是:

nohup fswatch -o ~/Notes -e "\\.git.*" | xargs -n 1 -I {} sh -c 'cd ~/Notes; git add -A; git commit --allow-empty-message -m ""' > /dev/null 2>&1 &'
感谢威尔·巴恩韦尔和whjm的帮助

此外,这是针对vim脚本的,因此格式必须略有不同(以防其他人正在寻找类似问题的解决方案):

请注意,Will Barnwell的错误之处在于
{..}
不是子shell,
sh-c
命令需要一个字符串。所以花括号是不必要的,在我的例子中添加了一个不需要的git提交消息


另外,当在这个vim脚本中使用vim
execute
函数时,整个命令必须用引号括起来。在单引号上加倍(请注意不要使用双引号)可以让
execute
函数将参数作为普通字符串接受,一切正常。

如果我将
sh~/auto_commit.sh
替换为
cd~/Notes&&git add-a&&git commit--allow empty message am”“
则不起作用。我希望避免使用外部脚本文件,而是以内联方式完成所有操作。您可以在~/Notes文件夹中启动nohup并使用
git commit-A…
,使其成为一个命令吗?我不希望这样做,因为此命令是由vim事件触发的,因此它位于不在
~/Notes
目录中的vim配置中。我想我可以把配置放在那里,并将其符号化,但不确定系统会认为
PWD
是什么。你能在子shell中运行它吗
{cd~/Notes;git add-A;git commit--allow empty message-am”“}
我错了,但我猜是我帮了忙
{…;}
不是子shell,您不能真正使用子shell作为
xargs
afaik的目标
autocmd BufWinEnter *.note silent! execute '!nohup fswatch -o . -e "\\.git.*" | xargs -n 1 -I {} sh -c ''git add -A; git commit --allow-empty-message -m ""'' > /dev/null 2>&1 &'