Skip to main content
added 390 characters in body
Source Link
Stéphane Chazelas
  • 585.2k
  • 96
  • 1.1k
  • 1.7k

In zsh, to reduce a list of files to the ones that exist, you can use the (N) glob qualifier appended to each element of the list:

files=(/opt/foo/lib.jar /opt/bar/lib.jar)
that_exist=($^files(N))

(($#that_exist > 0 )) && print -rl -- $that_exist

Note that contrary to ls, it can tell whether a file exists or not even if you don't have search access to its parent directory (as long as you still have read access), as it looks for corresponding entries in the directory without trying to access the file.

See also:

that_exist_after_symlink_resolution=($^files(N-^@))

Which selects the files that are not (^) a symlink (@) after symlink resolution (-). Equivalent to using ls -Ld.

In zsh, to reduce a list of files to the ones that exist, you can use the (N) glob qualifier appended to each element of the list:

files=(/opt/foo/lib.jar /opt/bar/lib.jar)
that_exist=($^files(N))

(($#that_exist > 0 )) && print -rl -- $that_exist

See also:

that_exist_after_symlink_resolution=($^files(N-^@))

In zsh, to reduce a list of files to the ones that exist, you can use the (N) glob qualifier appended to each element of the list:

files=(/opt/foo/lib.jar /opt/bar/lib.jar)
that_exist=($^files(N))

(($#that_exist > 0 )) && print -rl -- $that_exist

Note that contrary to ls, it can tell whether a file exists or not even if you don't have search access to its parent directory (as long as you still have read access), as it looks for corresponding entries in the directory without trying to access the file.

See also:

that_exist_after_symlink_resolution=($^files(N-^@))

Which selects the files that are not (^) a symlink (@) after symlink resolution (-). Equivalent to using ls -Ld.

added 37 characters in body
Source Link
Stéphane Chazelas
  • 585.2k
  • 96
  • 1.1k
  • 1.7k

In zsh, to reduce a list of files to the ones that exist, you can use the (N) glob qualifier appended to each element of the list:

files=(/opt/foo/lib.jar /opt/bar/lib.jar)
that_exist=($^files(N))

(($#that_exist > 0 )) && print -rl -- $that_exist

See also:

that_exist_after_symlink_resolution=($^files(N-^@))

In zsh, to reduce a list of files to the ones that exist, you can use the (N) glob qualifier:

files=(/opt/foo/lib.jar /opt/bar/lib.jar)
that_exist=($^files(N))

(($#that_exist > 0 )) && print -rl -- $that_exist

See also:

that_exist_after_symlink_resolution=($^files(N-^@))

In zsh, to reduce a list of files to the ones that exist, you can use the (N) glob qualifier appended to each element of the list:

files=(/opt/foo/lib.jar /opt/bar/lib.jar)
that_exist=($^files(N))

(($#that_exist > 0 )) && print -rl -- $that_exist

See also:

that_exist_after_symlink_resolution=($^files(N-^@))
Source Link
Stéphane Chazelas
  • 585.2k
  • 96
  • 1.1k
  • 1.7k

In zsh, to reduce a list of files to the ones that exist, you can use the (N) glob qualifier:

files=(/opt/foo/lib.jar /opt/bar/lib.jar)
that_exist=($^files(N))

(($#that_exist > 0 )) && print -rl -- $that_exist

See also:

that_exist_after_symlink_resolution=($^files(N-^@))