Given the following files
$ ls bar.txt baz.txt qux.txt I would like to save only the first txt file to a variable. I tried this
$ var=*.txt but it just saves all files
$ echo $var bar.txt baz.txt qux.txt I would like to do this using a wildcard if possible, and extglob is okay. The files here do not have spaces in the name but I would like the solution to also work for files with spaces.
After using kamituel’s answer I realized that this can work too
$ set *.txt $ echo $1 bar.txt