I'm trying to grab the first file matching a pattern and use that in a statement. Using the same steps as found in How can I get the first match from wildcard expansion? I wrote the following:#!/bin/bashfiles=(*.sql)firstfile=${files[0]}echo $firstfileecho The first file is $firstfileWhen I run this, the output is:sqlfile.sqlThe first file is *.sqlWhy does the value of $firstfile change based on the context?
Bash variable changes when inside quotes
bash;shell script;quoting
Take out the quotes in the files line, which leaves:#!/bin/bashfiles=(*.sql)firstfile=${files[0]}echo $firstfileecho The first file is $firstfile