[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
It's recommended not to use backticks to embed commands. It's been superseded by the $() form. I don't get any errors when I use location=$(<your_long_command>).
Edit: By the way, you can usually use "sed -e 'expression1' -e 'expression2', to combine your filters into a single command.
Also, I can't be 100% certain because I don't know what your input value is supposed to be, but I'm guessing the error is coming from a '/' value being in the sed input somewhere, messing up the reading of the separators. Or something like that. You can change the sed separator to another character instead (e.g. sed -e 's|ip address flag ||') which also eliminates the error messages.
By the way, just what exactly are you trying to extract from the lynx output anyway? It's likely we can clean up the command and make it more efficient. I tried running it with the ip address of google.com and got nothing.
Last edited by David the H.; 07-22-2009 at 10:33 AM.
Besides that, using all of perl, awk, sed, egrep and grep is, to say the least, an overkill. Either awk or perl should be enough to do all the parsing, or even sed. I'd also drop lynx in favor of wget -O - if possible, it seems to be much standard these days, but that's just my opinion.
I haven't looked deeply into the purpose of that one-liner, but it seems to me that you are creating complication for nothing.
Well, I'd help you to find a better way, but all I'm getting now is a "You reached your limit of 10 lookup queries per day" message, so I can't test it anymore. If you could provide a sample of the output we could work from instead, I'm sure we could give you a cleaner way to get that info.
My goal was to get a string representing the current city in which I am. (I push this string to a list which serves as the source for a web page on which some colleagues of mine can read my latest location update.) Looking for a simple way to extract my current location, I came across a working one liner at http://www.commandlinefu.com/ which produced relevant output for me: