0
shopt -s nullglob
array=(*)

Am I right in thinking that the purpose of the first line (shopt -s nullglob) is that in the event that there are unmatched patterns, they aren't added to the array?

I have a directory called unsorted_files. Now, were I use to array=(*) Am I right in assuming that is a wildcard, and would return ANY file? If then I were to specify array=(~/unsorted_files/"*jpg")

Would that then mean, all jpg files within the unsorted_files directory would then be added to the array and populate them as such as elements?

I have put "/*jpg" in between the "" but have been advised that this can cause the code to be ignored

0

1 Answer 1

2

You are right, the presence of " double-quotes prevents the shell globbing to be done. You need to populate the array without it. Also you need to use glob expression as *.jpg to match the jpg image extension files.

shopt -s nullglob
array=(~/unsorted_files/*.jpg)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.