Bash script question: command substitution and arrays
I'm writing up some scripts and I can see advantages to doing what I need to by hacking up a Bash script. In pseudo code this is what I want to do:
#!/bin/bash
# assume current directory has X number of .txt files
output=`ls *.txt`
read each filename into an array
So for example if the current directory contains "linode.txt cool.txt whatever.txt" I would like to have each of those filenames in an array, for example:
array[0] contains linode.txt
array[1] contains cool.txt
array[2] contains whatever.txt
Is there a simple way to do this? Note that I would prefer not to use awk in this situation as it is going to be used later after I parse out some data. I suppose I could also do this in Perl, but I would like to focus on learning some bash scripting right now.
1 Reply
For completeness, I needed to use parens around my command
output=(ls *.txt
)