0

Hi I am trying to print the public ip of the machine in a file using shell script. I am using the command

ip=${curl ipinfo.io/ip}

in my script file and it gives an error saying bad substitution. whereas this command works when i run it in command line. Is this the right way to get the ip through the script?

Thanks in advance!!

  • Possible duplicate of [How to set a variable to the output of a command in Bash?](https://stackoverflow.com/q/4651437/608639), [What is the difference between $(command) and \`command\` in shell programming?](https://stackoverflow.com/q/4708549/608639), [Command substitution: backticks or dollar sign / paren enclosed?](https://stackoverflow.com/q/9405478/608639), etc. – jww Aug 15 '18 at 13:16

1 Answers1

2

You are capturing the result of program so you should use $(). The following should work for you (with the -s parameter to curl stopping unnecessary output)

ip=$(curl -s ipinfo.io/ip)
borrible
  • 17,120
  • 7
  • 53
  • 75