5
6 killppp="eval kill -9 `ps ax | awk '/ppp/ { print $1 }'`"
7 # -------- ppp 的进程ID -------
8
9 $killppp # 这个变量现在成为了一个命令.
10
11
12 # 下边的命令必须以根用户的身份来运行.
t=table_3
table_3=24
echo "\"table_3\"=$table_3"
"table_3"=24
echo -n "\"t\"=";eval echo \$$t
"t"=24
t=table_3
new_val=387
table_3=$new_val
echo "\"table_3\"= $table_3"
"table_3"= 387
echo -n "\"t\"=";eval echo \$$t
"t"=387
Nils Radtke 展示了如何建立一个"dynamic"变量名字并且取出其中的值.当sourcing(包含)配置
文件时,这很有用.
################################Start
Script#######################################
#!/bin/bash
# ---------------------------------------------
# 这部分内容可能来自于单独的文件.
isdnMyProviderRemoteNet=172.16.0.100
isdnYourProviderRemoteNet=10.0.0.10
isdnOnlineService="MyProvider"
# ---------------------------------------------
remoteNet=$(eval "echo \$$(echo isdn${isdnOnlineService}RemoteNet)")
remoteNet=$(eval "echo \$$(echo isdnMyProviderRemoteNet)")
remoteNet=$(eval "echo \$isdnMyProviderRemoteNet")
remoteNet=$(eval "echo $isdnMyProviderRemoteNet")
echo "$remoteNet" # 172.16.0.100
#
============================================================
====
# 同时,它甚至能更好.
#
# 考虑下边的脚本,给出了一个变量getSparc,
#+ 但是没给出变量getIa64:
chkMirrorArchs () {
arch="$1";
if [ "$(eval "echo \${$(echo get$(echo -ne $arch |
sed 's/^\(.\).*/\1/g' | tr 'a-z' 'A-Z'; echo $arch |
sed 's/^.\(.*\)/\1/g')):-false}")" = true ]
then
return 0;
else
return 1;
fi;
}
getSparc="true"
unset getIa64
chkMirrorArchs sparc
echo $? # 0
# True
chkMirrorArchs Ia64
echo $? # 1
# False
# 注意:
# -----
# Even the to-be-substituted variable name part is built explicitly.
# The parameters to the chkMirrorArchs calls are all lower case.
# The variable name is composed of two parts: "get" and "Sparc" . . .
################################End
Script#########################################
阅读(1400) | 评论(0) | 转发(0) |