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.
Thanks again for your patients with me. Your help is truly appreciated.
I have an array problem. I am trying to get away from checking data files to see if they contain a string. That said I have put the data in an array in the script as an array. But I am having trouble figuring out how to make the check against the array. As in "if string_value is in array then; do something" I don't care what the array index number is in this instance, only that one of them has the string_value in it.
This is the code section that I am having issues with.
Code:
CDATA=("Pesach I" "Pesach II" "Pesach VII" "Pesach VIII" "Shavuot" "Rosh Hashanah I" "Rosh Hashanah II" "Yom Kippur" "Sukkot I" "Sukkot II" "Shemini Atzeret")
# Check if a YOMTOVE, reading set else ware.
if [[ "${CDATA[*]}" == *"$YOMTOVE"* ]]; then
echo "Is Yom Tove. The reading are handled by that function."
return
fi
It seams that the conditional check is failing and I have no idea why.
I wish I had know about the app called shellcheck http://www.shellcheck.net/ a long time ago. It has really helped me catch a lot of syntax errors. That doesn't make my scripts work any better but at least you all don't have to correct my simple errors anymore.
This is one of the smallest arrays I need to test against. The largest has 75 entries.
I am trying to get away from checking data files to see if they contain a string.
Why? grep is so easy and so fast. grep is made to do this task. I won't quarrel with your choice of language or your personal coding style... but must urge you to avoid doing easy things the hard way!
I guess I was under the impression that making the check without having to read disk would be faster and better. If that is not the case then I have no problem returning to reading disk to make such checks. Of coarse I am now most of a day into trying to get this figured out and I want to win this round.
Thanks again for your patients with me. Your help is truly appreciated.
I have an array problem. I am trying to get away from checking data files to see if they contain a string. That said I have put the data in an array in the script as an array. But I am having trouble figuring out how to make the check against the array. As in "if string_value is in array then; do something" I don't care what the array index number is in this instance, only that one of them has the string_value in it.
This is the code section that I am having issues with.
Code:
CDATA=("Pesach I" "Pesach II" "Pesach VII" "Pesach VIII" "Shavuot" "Rosh Hashanah I" "Rosh Hashanah II" "Yom Kippur" "Sukkot I" "Sukkot II" "Shemini Atzeret")
# Check if a YOMTOVE, reading set else ware.
if [[ "${CDATA[*]}" == *"$YOMTOVE"* ]]; then
echo "Is Yom Tove. The reading are handled by that function."
return
fi
It seams that the conditional check is failing and I have no idea why.
I wish I had know about the app called shellcheck http://www.shellcheck.net/ a long time ago. It has really helped me catch a lot of syntax errors. That doesn't make my scripts work any better but at least you all don't have to correct my simple errors anymore.
This is one of the smallest arrays I need to test against. The largest has 75 entries.
I guess I was under the impression that making the check without having to read disk would be faster and better.
If you read the same file multiple times, the kernel will cache the data in RAM so subsequent reads will be much faster. Regardless, your data is so small that I doubt you could notice the difference in speed. I would stick with grep since it makes the code so much shorter and easier to understand.
If you're really after speed, don't use a shell script.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.