Assign output to variable in Bash

前端 未结 2 414
闹比i
闹比i 2020-12-02 06:34

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/ nsupdat         


        
2条回答
  •  我在风中等你
    2020-12-02 07:27

    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
    

提交回复
热议问题