ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i'm trying to execute a shell script, i'm trying to use the values in an array for use in a sed command:
sed -n '/Sales ID: ${array[$i]}/,/Totals:/p'
that command creates empty files. so my guess is that its not recognizing the array as an array but as text?
how would i be able to utilize the array in the command?
thanks
i got it, didnt think that if i doubled up the single quotes that it would work, but this worked:
i got it, didnt think that if i doubled up the single quotes that it would work, but this worked:
sed -n '/Sales ID: '${array[$i]'}/,/Totals:/p'
Of course it would work: The quote ends the text, then you get the value of the array, then the next quote starts the text again. In bash, when strings are stuck together with no spaces in between, they are combined into one. (I hope that the fact that the right curly brace is after the quote mark is a mistake)
i didn't think that it would work only because the single quotes are used in the command, so if i broke it up it would think it was the next parameter for the command and error out. but it does work.... you learn something new every day.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.