Linux 执行另一个命令输出中给定的行

Linux 执行另一个命令输出中给定的行,linux,bash,pipe,Linux,Bash,Pipe,警告:这个问题不是关于git的使用,而是关于Linux中管道的使用,git命令在这里作为示例给出 具有这样的输出git push fatal: The current branch my_branch has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin my_branch 我想执行给定的命令,即,gitp

警告:这个问题不是关于git的使用,而是关于Linux中管道的使用,
git
命令在这里作为示例给出

具有这样的输出
git push

fatal: The current branch my_branch has no upstream branch.
To push the current branch and set the remote as upstream, use

   git push --set-upstream origin my_branch
我想执行给定的命令,即,
gitpush——设置上游原点my_分支

通过执行git push 2>&1 | tail-3我得到了git push——设置上游原点我的分支


问题:应该向下一个管道添加什么命令,以便执行给定的
git push
。因此,我可以执行git push 2>&1 | tail-3 |命令| u评估给定字符串

只需将管道连接到
bash
本身:

git push ... | bash
这将把前面管道中的标准输出发送到bash,然后bash将执行它

$ echo "echo 'hello'" | bash
hello
$ echo "uptime" | bash
 16:22:37 up  7:31,  3 users,  load average: 0,03, 0,14, 0,23

您可以将管道包装在命令替换中并
eval
它,而不是管道化到另一个命令。这将在当前shell会话中执行该命令。例如:

eval "$(printf 'some output 1\nsome output 2\necho execute me'| tail -1)";
## execute me

你想要的是
tail-1
,而不是
tail-3
。。。这只是最后一行。