是否有比以下更可取的 doing评价方式:
pattern= $x and $y x=1 y=2 eval "echo $pattern"
结果:
1 and 2
它只运行eval“echo ......”
,只是感到lo,可能有些不安全。 在巴什是否有更好的办法这样做?
是否有比以下更可取的 doing评价方式:
pattern= $x and $y x=1 y=2 eval "echo $pattern"
结果:
1 and 2
它只运行eval“echo ......”
,只是感到lo,可能有些不安全。 在巴什是否有更好的办法这样做?
https://www.gnu.org/software/gettext/manual/html_node/envsubst-Inue.html”rel=“nofollow noretinger”>envsubst from gettext,例如:
$ pattern= x=$x and y=$y
$ x=1 y=2 envsubst <<< $pattern
x=1 and y=2
一种安全的可能性是使用一种功能:
expand_pattern() {
pattern="$x and $y"
}
所有这一切都是如此。 然后使用如下:
x=1 y=1
expand_pattern
echo "$pattern"
您甚至可以将<条码>x和y
作为环境变量(因此,这些变量不在主要范围):
x=1 y=1 expand_pattern
echo "$pattern"
您的权利,eval
是本案的安全风险。 一种可能的办法:
pattern= The $a is $b when the $z is $x $c $g. # simulated input from user (use "read")
unset results
for word in $pattern
do
case $word in
$a)
results+=($(some_command)) # add output of some_command to array (output is "werewolf"
;;
$b)
results+=($(echo "active"))
;;
$c)
results+=($(echo "and"))
;;
$g)
results+=($(echo "the sky is clear"))
;;
$x)
results+=($(echo "full"))
;;
$z)
results+=($(echo "moon"))
;;
*)
do_something # count the non-vars, do a no-op, twiddle thumbs
# perhaps even sanitize %placeholders, terminal control characters, other unwanted stuff that the user might try to slip in
;;
esac
done
pattern=${pattern//$[abcgxz]/%s} # replace the vars with printf string placeholders
printf "$pattern
" "${results[@]}" # output the values of the vars using the pattern
printf -v sentence "$pattern
" "${results[@]}" # put it into a variable called "sentence" instead of actually printing it
产出将是“当月球满,天空清晰时,这些妇女正在活跃”。 同样的方案,如果模式是x美元,则美元为美元,因此,美元必须是美元。 那么,产出将是“整个月球已经消失,天空非常清楚,因此,死胎必须活跃。
I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...
How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks
I like to write bash shell scripts on my iPhone, put them in an app folder with an icon, plist, etc., so they execute like apps by tapping their icon on SpringBoard. This is not interactive like ...
From a programming standpoint, when you set the bash shell to use vi or emacs via set -o vi or set -o emacs What is actually going on here? I ve been reading a book where it claims the bash shell ...
I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...
I want perform sha1sum file1 and sha1sum file2 and perform bitwise OR operation with them using bash. Output should be printable i.e 53a23bc2e24d039 ... (160 bit) How can I do this? I know echo $(( ...
I m 试图撰写一个双面文字,处理一个文件清单,其名字在投入档案中每栏一栏储存,就像一个一样。
Is it possible to set the Screen Title using a shell script? I thought about something like sending the key commands ctrl+A shift-A Name enter I searched for about an hour on how to emulate ...