Comments (12)
I am having a similar question, but I don't really like the solution provided in this thread so far, maybe it's because I am running multiple entr processes without while loop.
Then I figured out another solution by creating a second shell script and source it. Hope it can help others.
file utils.sh
:
do_it() { echo it; }
do_that() { echo that; }
file run.sh
:
ls folder1/* | entr sh -c 'source utils.sh; do_it' &
ls folder2/* | entr sh -c 'source utils.sh; do_that'
from entr.
The problem there is that the function you defined is local to your current shell, so it cannot be run by external commands
$ do_it(){ echo Eita!; }
$ /usr/bin/time do_it
time: do_it: No such file or directory
0.00 real 0.00 user 0.00 sys
$ /bin/sh -c 'do_it'
sh: do_it: not found
from entr.
This code works, look:
while inotifywait -e close_write folder1/* folder2/*; do do_it; done
Even if I write:
export -f do_it
I got as a return: "entr: exec do_it: No such file or directory".
I think it has something to be with the use of "exec" by entr... Does it make sense? The error "exec...: No such file or directory" is not exclusive of entr.
from entr.
A function can be exported to a subshell, but you cannot execute a function with an external program. If you want to execute shell functions, you can write a loop such as this
#!/bin/sh
do_it(){ echo 'Eita!'; }
while true; do
do_it
ls folder1/* folder2/* | entr -pd -s 'kill $PPID'
done
(entr
doesn't have a "one-shot" option, so kill $PPID
is used to terminate itself when a file changes)
from entr.
Okay, I got it. Now, is there a way to run the function after entr is called? I tried:
entr -pd -s 'kill $PPID' && do_it
entr -pd -s 'kill $PPID' & do_it
entr -pd -s 'kill $PPID' ; do_it
but none of these worked...
from entr.
&
will background the process, and &&
will run only on exit code 0
so that's not what you want. The last option you listed should work
entr -pd -s 'kill $PPID' ; do_it
is equivalent to
entr -pd -s 'kill $PPID'
do_it
Running the shell with set -x
might help debug this
from entr.
Thank you very much.
It enters a loop:
entr -pd -s 'kill $PPID' ; do_it
entr: cannot create kqueue: Too many open files
from entr.
How many files are under the directories you're piping into entr
? Also what is the open file limit (ulimit -n
)?
here are the instructions for raising the max number of open files:
http://eradman.com/entrproject/limits.html
from entr.
How many files are under the directories you're piping into entr?
Files for an normal EPUB file. No more than 100.
ulimit -n
1024
I noticed that inotify was returning the same error. So I restart Ubuntu and then all is running fine.
If there is anything I can do to you, just say it. Thank you very much.
from entr.
Super! Glad it's working for you.
from entr.
A function can be exported to a subshell, but you cannot execute a function with an external program. If you want to execute shell functions, you can write a loop such as this
#!/bin/sh do_it(){ echo 'Eita!'; } while true; do do_it ls folder1/* folder2/* | entr -pd -s 'kill $PPID' done
(
entr
doesn't have a "one-shot" option, sokill $PPID
is used to terminate itself when a file changes)
@eradman This code won't exit with ctrl+c, is there a workaround to this??
from entr.
@OliverBrotchie, since 4.5 entr does have a one-shot option: -z
.
I bet ctrl-c
doesn't work because the shell loop doesn't give you time to interrupt it. Try replacing true
with sleep
#!/bin/sh
do_it(){ echo 'Eita!'; }
while sleep 0.1; do
do_it
ls folder1/* folder2/* | entr -pdz echo "reloading"
done
from entr.
Related Issues (20)
- entr is running twice HOT 5
- Tests are failing on archlinux HOT 3
- Minor doc proposal: A sentence to be explicit about some uses of '-s' HOT 2
- Error when running make install ../data.h: No such file or directory HOT 4
- File changes not detected in a certain condition HOT 5
- How to deal with user input? HOT 8
- `-r` option seems to force reboot on MacOS HOT 6
- entr: No regular files to watch in ruby HOT 8
- Alternatives to SIGTERM with -r HOT 11
- Use strlcpy with >=glibc-2.38 HOT 9
- Missing entr command on website HOT 1
- Ability to kill the process after a timeout if it fails to stop gracefully HOT 7
- `/_` marker and quotes. HOT 2
- doesn't this force the RLIMIT_NOFILES to be exactly 65536? HOT 11
- Feature request: provide a way to debounce triggers HOT 8
- fatal error: sys/sysctl.h: No such file or directory HOT 3
- `entr` apparently don't work when called from a Makefile task HOT 3
- Only the first event is handled when using entr to watch the script that runs entr HOT 9
- $0 isn't populated on macOS when using -s HOT 5
- Git tags are not signed HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from entr.