我想在shell脚本中暂停输入,并提示用户进行选择.标准的"是,否或取消"类型问题.如何在典型的bash提示符中完成此操作?
我添加了一个子模块:
git submodule add git://github.com/chneukirchen/rack.git rack
Run Code Online (Sandbox Code Playgroud)
.gitmodules创建的文件如下:
[submodule "rack"]
path = rack
url = git://github.com/chneukirchen/rack.git
Run Code Online (Sandbox Code Playgroud)
当然Git知道它:
git submodule status
30fb044db6ba5ea874ebc44a43bbd80a42676405 rack (1.3.0-64-g30fb044)
Run Code Online (Sandbox Code Playgroud)
我手动添加了一个子模块,例如,添加到该文件:
[submodule "redcloth"]
path = plugins/redcloth
url = git://github.com/jgarber/redcloth.git
Run Code Online (Sandbox Code Playgroud)
我重复了上一个命令:
git submodule init
Submodule 'rack' () registered for path 'rack'
git submodule update
(no output)
git submodule status
30fb044db6ba5ea874ebc44a43bbd80a42676405 rack (1.3.0-64-g30fb044)
Run Code Online (Sandbox Code Playgroud)
所以,就我所知,我手工添加的东西被忽略了.有没有办法让Git知道.gitmodules文件中手工添加的行?
注意:我还试图手动将这些行添加到.git/config文件中,但这也不起作用.
我正在尝试设置一个通用的 .gitmodules 文件,用作新项目始终需要的特定静态数量的子模块的模板。然后使用从 .gitmodules 恢复 git submodules 中显示的技术一次性初始化子模块:
#!/bin/sh
#set -e
git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
while read path_key path
do
url_key=$(echo $path_key | sed 's/\.path/.url/')
url=$(git config -f .gitmodules --get "$url_key")
branch_key=$(echo $path_key | sed 's/\.path/.branch/')
branch=$(git config -f .gitmodules --get "$branch_key")
if [ ! -d "$path" ]; then
echo URL - $url, Path - $path, Branch - $branch
if [ -n "$branch" ]; then
branch="-b $branch"
fi
git submodule add --force $branch …Run Code Online (Sandbox Code Playgroud) I would like to make a shell function that takes .gitmodules and iterates over each module executing certain commands based off of each submodules properties (e.g. <PATH> or <URL> or <BRANCH>).
?? The default format of .gitmodules:
[submodule "PATH"]
path = <PATH>
url = <URL>
[submodule "PATH"]
path = <PATH>
url = <URL>
branch = <BRANCH>
Run Code Online (Sandbox Code Playgroud)
?? Pseudocode:
def install_modules() {
modules = new list
fill each index of the modules list with each submodule & its …Run Code Online (Sandbox Code Playgroud) 在while循环中,如何编写交互式响应?
#!/bin/bash
shows=$(< ${HOME}/.get_iplayer/tv.cache)
# ...
# ... stuff with shows omitted ...
# ...
function print_show {
# ...
return
}
while read -r line
do
print_show "$line"
read -n 1 -p "do stuff? [y/n] : " resp # PROBLEM
# ...
# resp actions omitted
# ...
done <<< "$shows"
Run Code Online (Sandbox Code Playgroud)
因此,读取文件,进行“处理”,然后将所得的面向行的数据用于while read循环中
但是while循环中的读取行无法按预期工作,也就是说,它没有等待用户响应,这可能是由于while read封装了上下文所致。
您能否建议如何解决此问题或其他机制?