在Unix /猛砸,是" xargs的-p"在运行任何命令之前的好办法提示进行确认? [英] In Unix / Bash, is "xargs -p" a good way to prompt for confirmation before running any command?

查看:103
本文介绍了在Unix /猛砸,是" xargs的-p"在运行任何命令之前的好办法提示进行确认?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也问过如何做出任何指令要求是/否
在这个问题执行之前

I have asked how to make any command "ask for yes/no before executing" in the question

在bash,如何添加"确定[Y / N] QUOT;对任何命令或别名?

这似乎是在命令


hg push ssh://username@www.example.com//somepath/morepath

我也可以做到这一点。

I can also do this


echo ssh://username@www.example.com//somepath/morepath | xargs -p hg push

-p 是一个做的伎俩。这将被设置
作为一个别名,如 hgpushrepo 。这是一个很好的方式,
任何缺陷,或者没有更好的方法来做到这一点?我曾是
希望利用的东西是标准的Unix /猛砸
而不是写一个脚本来做到这一点。

The -p is the one that does the trick. This will be set as an alias, such as hgpushrepo. Is this a good way, any pitfalls, or any better alternatives to do it? I was hoping to use something that is standard Unix/Bash instead of writing a script to do it.

推荐答案

要使用别名的缺点是,它不会带参数。如果要概括了命令,所以你可以用任何用户名,主机名或路径使用它,你必须使用脚本或函数。

The disadvantage to using an alias is that it won't take parameters. If you wanted to generalize that hg command so you could use it with any username, hostname or path, you'd have to use a script or a function.

顺便说一句,使用脚本的的标准的Unix /打击。一个简单的脚本或函数一样简单(更容易,真的,因为增强的能力和通用性)作为别名。别名是有用的很短,极其简单的命令快捷键。他们经常是用来使一个选项为默认(如别名LS ='LS --color =自动')。

By the way, using a script is "standard Unix/Bash". A simple script or function is just as easy (easier, really, because of the increased power and versatility) as an alias. Aliases are useful for very short, extremely simple command shortcuts. Frequently they're used to enable an option as a default (eg. alias ls='ls --color=auto').

有关您经常使用不需要的参数(除了那些可以在最后追加)不变的命令,别名是完全正常的。并没有什么错的,你带路使用的xargs 。这是一个有点有点大材小用,它是一个外部可执行不必要的电话,但不应该在这种情况下是显著。

For unchanging commands that you use frequently that don't need arguments (except those that can be appended at the end), aliases are perfectly fine. And there's nothing wrong with using xargs in the way that you show. It's a little bit overkill and it's an unnecessary call to an external executable, but that shouldn't be significant in this case.

这篇关于在Unix /猛砸,是" xargs的-p"在运行任何命令之前的好办法提示进行确认?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆