Reputation: 367
I'm trying to load filenames to an array in bash. Currently, I'm using:
testarr=(csv/*.csv)
Which is giving me elements like
csv/filename.csv
How can I add only 'filename' to the array?
Thanks!
Upvotes: 2
Views: 640
Reputation: 34
This can be done also using basename -a:
testarr=($(basename -a csv/*.csv))
Upvotes: 0
Reputation: 295579
Easiest thing is first to add the entire name, then strip the parts you don't want using parameter expansion:
testarr=( csv/*.csv ) # load literal filenames
testarr=( "${testarr[@]##*/}" ) # strip off directory names
testarr=( "${testarr[@]%.csv}" ) # strip off extensions
Upvotes: 6