在这个特殊情况下,我想在Bash中添加一个确认
Are you sure? [Y/n]
对于Mercurial来说hg push ssh://username@www.example.com//somepath/morepath,它实际上是一个别名.是否有可以添加到别名的标准命令来实现它?
原因是hg push并且hg out听起来很相似,有时当我想要时hgoutrepo,我可能会意外地输入hgpushrepo(两者都是别名).
更新:如果它可以像是带有另一个命令的内置命令,例如:confirm && hg push ssh://...那个很棒......只是一个可以请求a yes或者no继续其余命令的命令yes.
我有一个文件夹,这是一个git repo.它包含一些文件和.gitmodules文件.现在,当我这样做git init,然后git submodule init,后者命令的输出是什么.我如何帮助git查看.gitmodules文件中定义的子模块,而无需git submodule add再次手动运行?
更新:这是我的.gitmodules文件:
[submodule "vim-pathogen"]
path = vim-pathogen
url = git://github.com/tpope/vim-pathogen.git
[submodule "bundle/python-mode"]
path = bundle/python-mode
url = git://github.com/klen/python-mode.git
[submodule "bundle/vim-fugitive"]
path = bundle/vim-fugitive
url = git://github.com/tpope/vim-fugitive.git
[submodule "bundle/ctrlp.vim"]
path = bundle/ctrlp.vim
url = git://github.com/kien/ctrlp.vim.git
[submodule "bundle/vim-tomorrow-theme"]
path = bundle/vim-tomorrow-theme
url = git://github.com/chriskempson/vim-tomorrow-theme.git
Run Code Online (Sandbox Code Playgroud)
这是这个目录的清单:
drwxr-xr-x 4 evgeniuz 100 4096 ???? 29 12:06 .
drwx------ 60 evgeniuz 100 4096 ???? 29 11:43 ..
drwxr-xr-x 2 evgeniuz 100 4096 ???? 29 …Run Code Online (Sandbox Code Playgroud) 我有一个shell脚本,基本上就是这样的
while true; do
read -r input
if ["$input" = "a"]; then
echo "hello world"
fi
done
Run Code Online (Sandbox Code Playgroud)
这一切都很好,很好,但我只是意识到必须点击ENTER在这种情况下提出了一个严重的问题.我需要的是脚本在按下键时响应,而不必按Enter键.
有没有办法在shell脚本中实现此功能?
我正在编写一个Linux Shell脚本来自动完成我在Ubuntu 11.04上做的一些事情.
基本上,我正在编写一个shell脚本来安装NGINX,MySQL和PHP,然后配置所有内容.我知道如何通过命令行完成所有事情.
但是,我不知道我将如何处理进程要求用户输入的部分.例如,我使用apt-get安装的某些内容会要求您进行确认,即(Y)es或(N)o.
我究竟如何处理shell脚本中的自动确认,即在被问到时自动确认是或否?
我基本上有一个bash脚本,它连续执行5个命令.我想添加一个逻辑,询问我"你想执行命令A",如果我说YES,执行命令,否则脚本跳转到另一行,我看到提示"你想执行命令B" .
该脚本非常简单,看起来像这样
echo "Running A"
commandA &
sleep 2s;
echo "done!"
echo "Running B"
commandB &
sleep 2s;
echo "done!"
...
Run Code Online (Sandbox Code Playgroud) 如何在Bash中询问是/否类型问题?
我问这个问题...... echo "Do you like pie?"
并得到答案...... read pie
如果答案是yes或开始,我该怎么办?y(是的,是的,等等,也会起作用).
使用zsh,我试图~/.zprofile在我交互式地询问是/否风格问题的地方迈出一步.起初我尝试了这种bash风格的方法,但我看到了这种形式的错误:
read: -p: no coprocess
(我知道通常zsh语法与bash不同 - 我尝试使用sh仿真命令emulate -LR sh- 但它没有区别).
这个页面暗示语法可能不同,所以在这个页面和zsh手册页的引导下,我尝试了这个:
read -q REPLY?"This is the question I want to ask?"
相反,它失败并出现以下形式的错误:
/home/user/.zprofile:5: no matches found: REPLY?"This is the question I want to ask?"
我怎么能用zsh问一个简单的是/否问题?理想情况下,命令只会吞下一个字符,无需按Enter/Return,并且"安全" - 即后续测试默认为no/false,除非输入"Y"或"y".
例
#!/bin/bash
INSTALL_PATH="/usr/local"
BFGMINER_INSTALL_PATH="${INSTALL_PATH}/bfgminer"
BFGMINER_REPO="https://github.com/luke-jr/bfgminer.git"
list_last_ten_bfgminer_tags () {
cd ${BFGMINER_INSTALL_PATH}
git for-each-ref --format="%(refname)" --sort=-taggerdate --count=10 refs/tags | cut -c 6-
}
clone_bfgminer () {
cd ${INSTALL_PATH}
git clone ${BFGMINER_REPO} ${BFGMINER_INSTALL_PATH}
}
echo "select number to switch tag or n to continue"
select result in master $(list_last_ten_bfgminer_tags)
do
# HOW DO I CHECK THE INDEX??????? <================================= QUESTION
if [[ ${result} == [0-9] && ${result} < 11 && ${result} > 0 ]]
then
echo "switching to tag ${result}"
cd ${BFGMINER_INSTALL_PATH}
git checkout …Run Code Online (Sandbox Code Playgroud)