So far I have found some examples of Bash select function usage with logical constructed options or Asterisk one (i.e select s in *). This last one lists all actual directory content.

So I would like to understand the following:

  1. What does * mean?

  2. How could I display another directory content?
    (I tried something as opt=$( ls path ) and select s in "$opt[@]", but it fails)

Any related links or examples are welcome.

1 Answer 1


The * is a so-called "glob" and will be expanded by the bash as "all files in the current directory", so it will basically expand to a space-separated list of all files in the current directory (which is the format commonly expected by many bash builtin flow-control constructs).

Globs can be used not only stand-alone but also as part of expressions, so assuming you have a directory stored in a bash variable $searchdir (be careful in naming bash variables in order not to accidentally overwrite essential environment variables such as $PATH) the construct

select s in "$searchdir"/*

will expand to "all files in $searchdir".

Note, however, that if the directory happens to be empty, the expression will amount to a literal * (or literally /the/actual/value/pointed/to/by/searchdir/*) unless you have set the nullglob option via

shopt -s nullglob

Then, if the directory is empty, the glob construct will expand to an empty list which is usually what you will want.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .