In Bash, how to add “Are you sure [Y/n]” to any command or alias?

前端 未结 17 2999
轮回少年
轮回少年 2020-11-29 15:11

In this particular case, I\'d like to add a confirm in Bash for

Are you sure? [Y/n]

for Mercurial\'s hg push ssh://username@www.example.com//some

17条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 15:24

    This may be a hack:

    as in question In Unix / Bash, is "xargs -p" a good way to prompt for confirmation before running any command?

    we can using xargs to do the job:

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

    of course, this will be set as an alias, like hgpushrepo

    Example:

    $ echo foo | xargs -p ls -l
    ls -l foo?...y
    -rw-r--r--  1 mikelee    staff  0 Nov 23 10:38 foo
    
    $ echo foo | xargs -p ls -l
    ls -l foo?...n
    
    $
    

提交回复
热议问题