Não há um caminho fácil. Por padrão, watch usa /bin/sh para executar comandos, mas recebe -x :
-x, --exec
Pass command to exec(2) instead of sh -c which reduces
the need to use extra quoting to get the desired effect.
No entanto, nada não funcionará com fish porque h function não é
exportado para o ambiente:
$ watch -n 5 --exec fish -c h
Every 5.0s: fish -c h comp: Wed Oct 10 21:30:14 2018
fish: Unknown command 'h'
fish:
h
^
Em bash você pode exportar uma função para o ambiente com export -f
e use-o dentro de watch assim:
$ h1 () {
> echo hi
> }
$ type h1
h1 is a function
h1 ()
{
echo hi
}
$ export -f h1
$ watch -n 60 bash -c h1
Every 60.0s: bash -c h1 comp: Wed Oct 10 21:29:22 2018
hi
Se você usar fish , poderá criar um script de wrapper e chamá-lo com watch :
$ cat stuff.sh
#!/usr/bin/env fish
function h
date
end
h
$ watch -n5 ./stuff.sh
Observe também que fish tem . e source para que você possa definir a função
em outro arquivo e ser capaz de reutilizá-lo em outros scripts como esse:
$ cat function
function h
echo hi
end
$ cat call.sh
#!/usr/bin/env fish
. function
h
$ watch ./call.sh