Home > Software engineering >  Meaning of -nt operator in shell script (zsh completion)
Meaning of -nt operator in shell script (zsh completion)

Time:05-10

I stumbled upon a Z shell (zsh) completion file, and I can't figure out what the -nt operator does.

if ! [ -r $cache -a -s $cache ] || [ "$squeezy" -nt $cache ]

What is the explanation? Is this even a valid operator, or is it rather a typo by the author?

Here is the whole file:

#compdef squeezy

local squeezy=`whence -p squeezy`
local cache="$HOME/.squeezy_zsh_completion_cache"

[ -z "$squeezy" ] && return 1
[ -x "$squeezy" ] || return 2

if ! [ -r $cache -a -s $cache ] || [ "$squeezy" -nt $cache ]
then
   command squeezy -options | tr ' ' '\n' | grep '^-[a-zA-Z0-9]' > $cache
fi

[ -r $cache -a -s $cache ] || return 4

_arguments `cat $cache`

CodePudding user response:

Running man zshall and searching for -nt shows:

file1 -nt file2

true if file1 exists and is newer than file2.

  • Related