我要寻找的是在Linux中将一个命令的输出用作“完全相同的其他命令”?
例如:
[root@ip-10-0-0-136 ~]# echo hi
hi
[root@ip-10-0-0-136 ~]
现在我要将此“ hi”用作立即命令并执行。 我怎样才能做到这一点 ?
因此,应类似于:
[root@ip-10-0-0-136 ~]# echo hi
hi
[root@ip-10-0-0-136 ~]# hi
有可能吗?
请提出建议
编辑1:
请参考具体示例:
[root@ip-10-0-0-136 ~]# aws ecr get-login --no-include-email --region eu-central-1
docker login -u AWS -p eyJwYXlsb2FkIjoibWJ3aVJhNmpwbFkzVjhnVFA1SlFnTXhDWHZoYUlKaVJKVGxIQjdheVVOMkk0NzM5NHFKelVYOXUxN21EMmVRMkx4dmJickNOWDY3bFNjL2hMSWE3c0dDT2cyOWxXb25NUVEzZW1sL2szajlUYTc0cHBFVmhWVU1vSUJVdGVMcWhKZ3k3NkpjWGVWR283dkU4amVCWGo0eDdVU3ZUMUc4WE5xRXBKSlRyQlh6c2M0TnZMME9iR2lHa1BqeFUrS2wrc052clUyY3pLVW56bTZEZFNRSHFlckZFU1ZnMEFkTWV4bHluMzQxUDhzWFNpdDBzYm1zZDlIYUFnSUM0Q3A2a1FZQVlZL3NUYXN3Zk9BZytIbVpxaGY2NFdzdEYxajBsNmlnR2NnMEkzYmJ0czl5c3REb0VENnBtK0FqZ2lLN1hpUlNPL01raEt5bnRTZ1lGSnB3cjJxb0RTZDdkUWE1QUtoaFhQdy9MU3kzMlZUVDRyRCsyTVU5TXRKY2FWMjBINFJKcnN3c08yUWFJaHE4VGsrZGZlcUxaSHowb1RNZmxlaDYxbDV0emN1bkNBOHdKeDIxcEliaXlQbFR4dWVrczdzbW9hamEraThxUjFlMi9XUHhUbGdKd2g1Y2FEd1RhbitJdDBtNDZ1ckZuWjMxOXpWelgyUm9vMG0ycm5rUk1iYkhmT2dRS2RPSUs0V0tzQm91eDRic2o2bHJVeGk4dGFOdEgyNmdPUG1oRUlHaVJRMlRqTThQbFlDRDZ6dEZHc3F3NnRRbmVwZ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xBc28xcDFFbCt3PSIsInZlcnNpb24iOiIyIiwidHlwZSI6IkRBVEFfS0VZIiwiZXhwaXJhdGlvbiI6MTU0Nzc2OTEzNX0= https://890543041640.dkr.ecr.eu-central-1.amazonaws.com
[root@ip-10-0-0-136 ~]# !$
eu-central-1
bash: eu-central-1: command not found
[root@ip-10-0-0-136 ~]# $
bash: $: command not found
[root@ip-10-0-0-136 ~]#
答案 0 :(得分:2)
您可以使用命令替换:
[root@ip-10-0-0-136 ~]# $(echo hi)
与
相同[root@ip-10-0-0-136 ~]# `echo hi`
答案 1 :(得分:2)
您可以使用$(aws ecr get-login --no-include-email --region eu-central-1)
这将在括号中执行命令的输出。在您的情况下,命令docker login -u AWS -p eyJwYX..
将被执行
引用:https://superuser.com/questions/935374/difference-between-and-in-shell-script
答案 2 :(得分:1)
是的,可以使用!$
。如果我使用
[root@ip~ppp]$ echo cd
cd
[root@ip~ppp]$ !$
cd
[root@ip~]$
执行cd
命令
答案 3 :(得分:0)
我认为您可以简单地通过管道传输一些输出并将其提供给bash命令。
echo 'ls' | bash