Giter VIP home page Giter VIP logo

Comments (12)

sgon00 avatar sgon00 commented on May 10, 2024 1

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.

eradman avatar eradman commented on May 10, 2024

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.

atipico avatar atipico commented on May 10, 2024

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.

eradman avatar eradman commented on May 10, 2024

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.

atipico avatar atipico commented on May 10, 2024

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.

eradman avatar eradman commented on May 10, 2024

& 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.

atipico avatar atipico commented on May 10, 2024

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.

eradman avatar eradman commented on May 10, 2024

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.

atipico avatar atipico commented on May 10, 2024

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.

eradman avatar eradman commented on May 10, 2024

Super! Glad it's working for you.

from entr.

OliverBrotchie avatar OliverBrotchie commented on May 10, 2024

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)

@eradman This code won't exit with ctrl+c, is there a workaround to this??

from entr.

eradman avatar eradman commented on May 10, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.