Skip to main content
3 of 4
added 301 characters in body
Stéphane Chazelas
  • 585.2k
  • 96
  • 1.1k
  • 1.7k

Yes, doing filename expansion upon command substitution and other expansions is generally not wanted¹ and not done by default in zsh except in sh/ksh emulation (globsubst option).

While you could use ${~$(...)} to request the use of globsusbt for that particular command substitution (and by the way, you don't need the paste part, both space and newline are in the default value of $IFS), a much better way to do it with zsh would be:

ids=($(qstat))
tail -F logs/*${^ids}

Note that if any of those globs fail to match any file, the command will be aborted.

tail -F logs/*${^ids}(N)

would avoid that but would run tail -F without argument if there was no file at all.

You could also make it:

logs=(logs/*${^$(qstat)}(N))
(($#logs)) && tail -F $logs

¹ The fact that bash and other Bourne-like shells do it could be seen as a bug. That's one reason why you need to quote all your variables there, or why you need set -o noglob before running using an unquoted $(...) when you only want the splitting part of that split+glob. All more modern shells that don't carry the Bourne shell baggage like rc, es or fish don't do it either.

Stéphane Chazelas
  • 585.2k
  • 96
  • 1.1k
  • 1.7k