使用 ls 和 shell globs 观察命令

Ale*_*lex 3 bash watch wildcards

我尝试运行命令

watch -n1 ls foo/bar*
Run Code Online (Sandbox Code Playgroud)

我想列出foo/bar*每秒匹配的文件。然而,实际发生的是 shell 扩展了 glob 并且watch运行的是,比如说,

ls foo/bar1.txt foo/bar2.txt
Run Code Online (Sandbox Code Playgroud)

因此,如果foo/bar3.txt稍后添加另一个文件,它将不会显示在输出中。有没有一种巧妙的方法来做到这一点,而无需创建包含

ls foo/bar*
Run Code Online (Sandbox Code Playgroud)

Dop*_*oti 8

将其用强引号括起来,以便不会立即解析通配符:

$ watch -n1 'ls foo/bar*'
Run Code Online (Sandbox Code Playgroud)