我想嵌套多个字符串,如下所示:
sudo ssh server "awk "/pattern/{print "hello"}1" file > file.tmp"
Run Code Online (Sandbox Code Playgroud)
使用2个嵌套引号,我设法让我的命令工作:
awk "/pattern/{print \"hello\"}1" file > file.tmp
Run Code Online (Sandbox Code Playgroud)
我不能使用单引号('),因为我的命令中有变量.有人能帮我吗 ?
提前致谢.
我已经尝试让这件事工作几个小时,但我无法让它工作:
if [ "$P" = "SFTP" -a "$PORT" != "22" ] || [ "$P" = "FTPS" && [ "$PORT" != "990" -a "$PORT" != "21" ] ] ; then
有人能帮我吗 ?我知道多个条件可以这样写:
if [ "$P" = "SFTP" ] && [ "$PORT" != "22" ]; then
但我怎样才能像第一个例子一样叠加这些条件呢?
bash if-statement nested multiple-conditions conditional-statements
我只是编写了一个用于管理多个并行ssh命令的bash脚本.为了解析参数,我使用这段代码:
#!/bin/bash
# replace long arguments
for arg in "$@"; do
case "$arg" in
--help) args="${args}-h ";;
--host|-hS) args="${args}-s ";;
--cmd) args="${args}-c ";;
*) [[ "${arg:0:1}" == "-" ]] && delim='' || delim="\""
args="${args}${delim}${arg}${delim} ";;
esac
done
echo "args before eval : $args"
eval set -- $args
echo "args after eval : $args"
while getopts "hs:c:" OPTION; do
echo "optarg : $OPTARG"
case $OPTION in
h) usage; exit 0;;
s) servers_array+=("$OPTARG");;
c) cmd="$OPTARG";;
esac
done
Run Code Online (Sandbox Code Playgroud)
所以我可以使用例如-s, - host或-hS来获得相同的结果.除了一件事,一切都很好.
如果我在参数中放入一个变量,它将被评估.
我已经创建了一个带有配置页面的模块,一切运行良好,但我的配置页面似乎无穷无尽.所以想在评论的配置页面中创建标签:
http://i.stack.imgur.com/Penba.png
我搜索了很多,并试图分析注释模块代码失败:
有人可以帮助我做到这一点,或者至少让我领先?
在此先感谢BDR