Generating iteratable arrays in bash
I am wanting a command to populate an array with its output, for example:
slocate newfile > An_Array Which would then allow a second command to iterate through An_Array, such as: Code:
for x in An_Array Any thoughts? |
So your looking for something like?
Code:
#!/bin/sh Code:
$ ./test One two three |
Hmmm ... looks about right. Let me test it out and get back to you.
Thanx |
Thanks for the script leonscape. The mechanics seem okay, but now I need to figure out how to get the output of slocate to be loaded into An_Array. I tried slocate myfile_name > An_Array which gave me a text file of the output of slocate ... which was not what I had in mind.
How could I: (a) accept input from a user (i.e. what file they want to slocate), and (b) dynamically populate an array with the output of slocate so that it can be iterated over? Thanks |
$1 works for command line inputs. So that is what the user could enter to the command. i think the easiest way of iterating the slocate return is to push it out to a temp file and read it into an array. Not being a Bash guru, i couldn't think of a way to redirect a command output to an array. So what I would end up with is:
Code:
#!/bin/sh |
All times are GMT -5. The time now is 07:09 AM. |