【问题标题】:Bash returning my variable empty in text fileBash 在文本文件中返回我的变量为空
【发布时间】:2015-11-17 04:44:27
【问题描述】:

我正在尝试制作简单的 bash,它会找到我的 IP,然后在 .txt 模板中更新它。当我运行 bash 时,我的文件充满了空白点而不是 IP 地址。

alias wanip='curl -s http://whatismijnip.nl |cut -d " " -f 5'
wanip
sed -i -e "s/\${ip}/"$wanip"/" config.txt

【问题讨论】:

  • 如果wanip 是别名,那么$wanip 应该是什么?您是不是要运行 wanip(反引号?)并替换它的输出?

标签: bash shell unix command-line sh


【解决方案1】:

试试这个:

wanip="$(curl -s http://whatismijnip.nl |cut -d " " -f 5)"
sed -i -e "s/\${ip}/"$wanip"/" config.txt

我想 $ip 不是变量。

【讨论】:

    猜你喜欢
    • 2013-09-20
    • 2015-11-13
    • 1970-01-01
    • 2012-02-27
    • 1970-01-01
    • 2012-08-08
    • 2013-10-07
    • 2021-11-25
    • 2012-01-30
    相关资源
    最近更新 更多