Define function in fish, use it with watch
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I want to define a function, and call that function every n seconds. As an example:
function h
echo hello
end
Calling h
works:
david@f5 ~> h
hello
But when using watch, it doesn't...
watch -n 60 "h"
...and I get:
Every 60.0s: h f5: Wed Oct 10 21:04:15 2018
sh: 1: h: not found
How can I run watch
in fish, with the function I've just defined?
function fish watch
add a comment |Â
up vote
0
down vote
favorite
I want to define a function, and call that function every n seconds. As an example:
function h
echo hello
end
Calling h
works:
david@f5 ~> h
hello
But when using watch, it doesn't...
watch -n 60 "h"
...and I get:
Every 60.0s: h f5: Wed Oct 10 21:04:15 2018
sh: 1: h: not found
How can I run watch
in fish, with the function I've just defined?
function fish watch
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to define a function, and call that function every n seconds. As an example:
function h
echo hello
end
Calling h
works:
david@f5 ~> h
hello
But when using watch, it doesn't...
watch -n 60 "h"
...and I get:
Every 60.0s: h f5: Wed Oct 10 21:04:15 2018
sh: 1: h: not found
How can I run watch
in fish, with the function I've just defined?
function fish watch
I want to define a function, and call that function every n seconds. As an example:
function h
echo hello
end
Calling h
works:
david@f5 ~> h
hello
But when using watch, it doesn't...
watch -n 60 "h"
...and I get:
Every 60.0s: h f5: Wed Oct 10 21:04:15 2018
sh: 1: h: not found
How can I run watch
in fish, with the function I've just defined?
function fish watch
function fish watch
edited 18 mins ago
Jeff Schaller
33.8k851113
33.8k851113
asked 37 mins ago
user258532
1193
1193
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
There is no easy way. By default watch
uses /bin/sh
to run commands but takes -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.
However, nothing will not work with fish
because h
function is not
exported to environment:
$ 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
^
In bash
you could export a variable to environment with export -f
and use it inside watch
like this:
$ 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
If you use fish
you can create a wrapper script and call it with watch
:
$ cat stuff.sh
#!/usr/bin/env fish
function h
date
end
h
$ watch -n5 ./stuff.sh
Also note that fish
has .
and source
so you can define function
in another file and be able to re-use it in other scripts like that:
$ cat function
function h
echo hi
end
$ cat call.sh
#!/usr/bin/env fish
. function
h
$ watch ./call.sh
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
There is no easy way. By default watch
uses /bin/sh
to run commands but takes -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.
However, nothing will not work with fish
because h
function is not
exported to environment:
$ 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
^
In bash
you could export a variable to environment with export -f
and use it inside watch
like this:
$ 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
If you use fish
you can create a wrapper script and call it with watch
:
$ cat stuff.sh
#!/usr/bin/env fish
function h
date
end
h
$ watch -n5 ./stuff.sh
Also note that fish
has .
and source
so you can define function
in another file and be able to re-use it in other scripts like that:
$ cat function
function h
echo hi
end
$ cat call.sh
#!/usr/bin/env fish
. function
h
$ watch ./call.sh
add a comment |Â
up vote
0
down vote
There is no easy way. By default watch
uses /bin/sh
to run commands but takes -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.
However, nothing will not work with fish
because h
function is not
exported to environment:
$ 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
^
In bash
you could export a variable to environment with export -f
and use it inside watch
like this:
$ 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
If you use fish
you can create a wrapper script and call it with watch
:
$ cat stuff.sh
#!/usr/bin/env fish
function h
date
end
h
$ watch -n5 ./stuff.sh
Also note that fish
has .
and source
so you can define function
in another file and be able to re-use it in other scripts like that:
$ cat function
function h
echo hi
end
$ cat call.sh
#!/usr/bin/env fish
. function
h
$ watch ./call.sh
add a comment |Â
up vote
0
down vote
up vote
0
down vote
There is no easy way. By default watch
uses /bin/sh
to run commands but takes -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.
However, nothing will not work with fish
because h
function is not
exported to environment:
$ 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
^
In bash
you could export a variable to environment with export -f
and use it inside watch
like this:
$ 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
If you use fish
you can create a wrapper script and call it with watch
:
$ cat stuff.sh
#!/usr/bin/env fish
function h
date
end
h
$ watch -n5 ./stuff.sh
Also note that fish
has .
and source
so you can define function
in another file and be able to re-use it in other scripts like that:
$ cat function
function h
echo hi
end
$ cat call.sh
#!/usr/bin/env fish
. function
h
$ watch ./call.sh
There is no easy way. By default watch
uses /bin/sh
to run commands but takes -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.
However, nothing will not work with fish
because h
function is not
exported to environment:
$ 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
^
In bash
you could export a variable to environment with export -f
and use it inside watch
like this:
$ 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
If you use fish
you can create a wrapper script and call it with watch
:
$ cat stuff.sh
#!/usr/bin/env fish
function h
date
end
h
$ watch -n5 ./stuff.sh
Also note that fish
has .
and source
so you can define function
in another file and be able to re-use it in other scripts like that:
$ cat function
function h
echo hi
end
$ cat call.sh
#!/usr/bin/env fish
. function
h
$ watch ./call.sh
answered 6 mins ago
Arkadiusz Drabczyk
7,39521633
7,39521633
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f474628%2fdefine-function-in-fish-use-it-with-watch%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password