BASH Script. Result of command input into variable
Hi, I have been trying to figure this out and also new to bash scripting as well. How can I put the result of a command into a variable such as this.
CURRENT='wget -O - -q icanhazip.com' So if I would run echo $CURRENT I would get an IP address? Right now echo returns the command. I can't seem to figure out how exactly to do this. In the end I need two variables. One an IP address returned as my current external IP and the second a variable read from a file that would be an IP address as well. Thanks! |
Here is what you need:
Code:
#!/bin/bash Code:
`wget -O - -q icanhazip.com` Josh |
Thanks Josh, did the trick!
-Brian |
No problem! Please mark your thread as solved using the thread tools located at the top of the page, thanks!
Cheers, Josh |
Note that $(..) is highly recommended over `..`.
A while back I wrote up a script/function that polls a random site for your external ip address, and keeps trying until it gets a successful hit. You can easily edit the list if you discover new ones or one goes bad. I currently have seven working addresses. Code:
#!/bin/bash |
All times are GMT -5. The time now is 09:49 PM. |