bash split array and assign a variable to an element
wonder if you can help. I have a bash script which is generating an array...
1 a z
2 b y
3 c x
gives the array three elements. Is there a way i can split these elements based on column and assign them to a variable?
column1=$number (1, 2 and 3)
column2=$letter (a, b and c)
column3=$anotherletter (z, y and x)
i can perform an action on each e.g.
Please use ***[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do not use quote tags, bolding, colors, "start/end" lines, or other creative techniques.
Your best bet is simply to use another read command, either with separate variables or another array.
string manipulations in bash
awesome david, works well. thanks
Great. Please mark the thread as solved.
Oh, and I almost forgot, be sure to always quote your variable expansions, otherwise shell word-splitting will take place (with a few minor exceptions, such as inside [[..]]).
It's vital in scripting to understand how the shell handles arguments and whitespace. Learn how to do it right!
|All times are GMT -5. The time now is 06:32 PM.|