• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

*nix bash shell question....

Need4Speed

Diamond Member
maybe someone can help me out here...

Every our I run a command to check my WAN ip and then write it into a file called wan.ip. Now I want to use that ip in another command...lets say ping for example. How would I go about pulling the ip from the file and direct it to the ping command?


Hope I'm being clear on my question....TIA.

-P
 
If the IP address is in the file ~/wan.ip, you would do

ping `cat ~/wan.ip`

(Those are the quotes from the tilde key, not the apostrophe key).

Of course, if wan.ip has anything else in it, you'll need to process the address out using grep or similar.
 
As an added explanation to what cleverhandle said, the `` are special characters. I believe this works in most of the shells out there (BOURNE compatible shells and BASH definitely work, csh should, not sure about others though).

We have the file wan.ip and want to ping the ip address in that file. The easiest way is to use the `` characters. These characters are similar to parintheses(sp?) in algebra. They tell the shell to execute that command first:

ping `cat ~/wan.ip`

This command executes cat ~/wan.ip first, and uses the results of that command as the variables ($2) for the ping command. Ill draw the steps out:

COMMAND: ping `cat ~/wan.ip`
First process: cat ~/wan.ip
Result: 127.0.0.1
Second command: ping 127.0.0.1



If someone wants to clean that up and post it/add it to the Linux FAQ thread feel free. 🙂
 
Back
Top