【发布时间】:2014-12-02 16:21:12
【问题描述】:
我在使用 echo 打印两个变量时遇到问题。以下是脚本中的代码 sn-p:-
tdaydatefile=$(date +'%m%d%Y')
ip=$(ip route get 8.8.8.8 | awk 'NR==1 {print $NF}')
echo "Dumping all network connections to $HOME/MyLog/netstat_$ip_$tdaydatefile.csv!"
当脚本运行时,它只打印在下面:-
Dumping all network connections to /root/MyLog/netstat_12022014.csv!
它不打印系统的ip地址(ip变量)。如果我在 echo 中将 ip 替换为 tdaydatefile,它会打印 ip 并忽略 tdaydatefile 变量。
知道这里有什么问题吗?
【问题讨论】:
-
ip_是一个有效的变量名,所以你正在转储一个未定义的变量。试试{$ip},或者改用破折号...-$ip-$tday。 -
你应该用你正在使用的语言来标记它。
-
@MarcB:我认为您的意思是
netstat_${ip}_$tdaydatefile,其中左大括号位于 $ 之后和变量名之前。 -
干杯,谢谢你们..
标签: shell