LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-29-2015, 03:21 PM   #1
Entropy1024
Member
 
Registered: Dec 2012
Location: UK
Distribution: Ubuntu 16 & 17
Posts: 131

Rep: Reputation: Disabled
Passing Curl result to a variable in a Bash script


I'm attempting to get my external IP as a variable (myextip) using curl in a bash script called extip.sh, however I can't quite work out the syntax. I have read a few examples and my best guess to make it work is below. But when I run it it returns:
extip.sh: 5: pcstatus.sh: -s: not found

Code:
#!/bin/bash
myextip= $(curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
Can you please help me find the correct syntax?
Many thanks
Tim
 
Old 10-29-2015, 03:44 PM   #2
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
I don't have curl installed, but here's how I would do it with wget:
Code:
MY_EXT_IP=$(wget -qO - http://icanhazip.com/)
I see that there is a space in your assignment:
Code:
myextip= $...
This will always fail. You cannot use spaces when assigning a variable in Bash. It has to be like this:
Code:
myextip=$...
Best regards,
HMW

Last edited by HMW; 10-29-2015 at 03:46 PM.
 
1 members found this post helpful.
Old 10-29-2015, 03:50 PM   #3
Entropy1024
Member
 
Registered: Dec 2012
Location: UK
Distribution: Ubuntu 16 & 17
Posts: 131

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by HMW View Post
I don't have curl installed, but here's how I would do it with wget:
Code:
MY_EXT_IP=$(wget -qO - http://icanhazip.com/)
I see that there is a space in your assignment:
Code:
myextip= $...
This will always fail. You cannot use spaces when assigning a variable in Bash. It has to be like this:
Code:
myextip=$...
Best regards,
HMW
Thank you very much.
Tim
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] BASH Script. Result of command input into variable bcyork Linux - Newbie 4 12-06-2011 12:57 PM
[SOLVED] passing variable through script (bash) ted_chou12 Programming 1 11-20-2011 10:17 AM
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 04:11 AM
bash script: how to assign an output (not the result) to a variable? Singing Banzo Programming 8 10-01-2006 06:29 PM
cannot export result from awk into a variable in a bash script Emmanuel_uk Linux - Newbie 4 03-07-2005 01:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration