卷曲的输出分配给在bash变量 [英] Assign curl output to variable in bash

查看:114
本文介绍了卷曲的输出分配给在bash变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想袅袅的输出分配到像这样一个变量:

I'm trying to assign the output of curl into a variable like so:

#!/bin/sh

$IP=`curl automation.whatismyip.com/n09230945.asp`

echo $IP

sed s/IP/$IP/ nsupdate.txt | nsupdate

然而,当我运行该脚本会发生以下情况:

However, when I run the script the following happens:

./ update.sh:3:= [我的IP地址]:找不到

我怎样才能输出到 $ IP 是否正确?

How can I get the output into $IP correctly?

推荐答案

在外壳,你不把$在你为变量赋值的前面。你只当你指的是变量使用$ IP。

In shell, you don't put a $ in front of a variable you're assigning. You only use $IP when you're referring to the variable.

#!/bin/bash

IP=$(curl automation.whatismyip.com/n09230945.asp)

echo "$IP"

sed "s/IP/$IP/" nsupdate.txt | nsupdate

这篇关于卷曲的输出分配给在bash变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆