一般评论:任何对这个问题提供新的有用见解的新答案都将获得奖励。
的击参考手册提到击支持以下for循环结构:
for name [ [in [words ...] ] ; ] do commands; done
for (( expr1 ; expr2 ; expr3 )) ; do commands ; done
Run Code Online (Sandbox Code Playgroud)
令人惊讶的是,以下 for 循环结构也是有效的:
for i in 1 2 3; { echo $i; }
for ((i=1;i<=3;++i)); { echo $i; }
Run Code Online (Sandbox Code Playgroud)
这些不寻常的构造根本没有记录。无论是猛砸手册中,猛砸男子的页面,也不Linux文档计划使这些结构的任何提及。
在研究语言语法时,可以看到使用开闭大括号 ( { commands; }) 作为替代方案do commands; done是一种有效的构造,该构造适用于 for 循环和 select 语句,并且可以追溯到Bash-1.14.7
[1]。
另外两个循环结构:
until test-commands; do …Run Code Online (Sandbox Code Playgroud) 偶尔我使用bash命令替换上一个命令中的字符串:
^foo^bar
Run Code Online (Sandbox Code Playgroud)
今天我想在下面的行中替换所有出现的checkbox`radio:
$ git mv _product_checkbox_buttons.html.erb _product_checkbox_button.html.erb
$ ^checkbox^radio
git mv _product_radio_buttons.html.erb _product_checkbox_button.html.erb
Run Code Online (Sandbox Code Playgroud)
所以它只替换第一次出现.如何更换所有出现的内容?
bash --version
GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)
Copyright (C) 2007 Free Software Foundation, Inc.
Run Code Online (Sandbox Code Playgroud) 在bash中,可以转义包含空格的参数.
foo "a string"
Run Code Online (Sandbox Code Playgroud)
这也适用于命令或函数的参数:
bar() {
foo "$@"
}
bar "a string"
Run Code Online (Sandbox Code Playgroud)
到目前为止一切都很好,但是如果我想在调用之前操纵参数foo呢?
这不起作用:
bar() {
for arg in "$@"
do
args="$args \"prefix $arg\""
done
# Everything looks good ...
echo $args
# ... but it isn't.
foo $args
# foo "$args" would just be silly
}
bar a b c
Run Code Online (Sandbox Code Playgroud)
那么当参数包含空格时,如何构建参数列表?
我有一个需要很多时间才能完成的脚本.
我宁愿退出并稍后检索其输出,而不是等待它完成.
我试过了;
at -m -t 03030205 -f /path/to/./thescript.pl
nohup /path/to/./thescript.pl &
我还验证了这些进程实际存在ps并at -l依赖于我使用的调度语法.
当我退出shell时,这两个进程都会死掉.有没有办法在关闭连接时阻止脚本终止?
我们这里有crons并且它们已经设置好并且正常工作,但我想使用at或nohup用于一次性脚本.
我的语法有问题吗?有没有其他方法可以产生预期的结果?
screen或disown- 他们没有安装在我的HP Unix设置中,我也无法安装它们 bash ×3
arguments ×1
at-job ×1
history ×1
keep-alive ×1
nohup ×1
scheduling ×1
sh ×1
shell ×1
unix ×1
whitespace ×1