8

I tried running the command

watch -n1 ls foo/bar*

which I want to list files matching foo/bar* every second. However, what actually happens is that the shell expands the glob and what watch runs is, say,

ls foo/bar1.txt foo/bar2.txt

Thus, if another file foo/bar3.txt is added later it won't show up in the output. Is there a neat way to do this without creating a script file containing

ls foo/bar*

1 Answer 1

20

Wrap it in strong quotes so that the wildcard isn't parsed immediately:

$ watch -n1 'ls foo/bar*'
3
  • And what is the difference between single and double quotes in this case? Commented Apr 3, 2018 at 23:50
  • Single quotes in bash don't perform shell expansion (wildcards and variables remain in their original form), double quotes in bash performs wildcard expansion. You can use this fact in many places. Commented Sep 26, 2019 at 19:39
  • 1
    elegant. Faced same issue - didn't expect answer was simple one.
    – mtk
    Commented Mar 11 at 5:44

You must log in to answer this question.

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