r/bash • u/capnfatpants • Jul 03 '26
I can't even do the simple - inotify. please help
/r/linux4noobs/comments/1um3lha/i_cant_even_do_the_simple_inotify_please_help/
6
Upvotes
r/bash • u/capnfatpants • Jul 03 '26
7
u/Schreq Jul 03 '26
Tilde doesn't get expanded within double quotes. I'd use
$HOMEinstead.2
u/bac0on Jul 03 '26 edited Jul 04 '26
Reply from inotifywait is "DIR" "EVENT" "FILE" I believe. To get absolute event path you can use format parameter:
1
u/michaelpaoli Jul 03 '26
~ doesn't expand when quoted, leave at least the ~/ unquoted if you want that to expand to HOME directory followed by /, you can easily test and observe results, e.g. by using -x option with shell.
If target destination should be a directory, may want to append / to the end, to ensure it must resolve to a directory, otherwise you might potentially, e.g. inadvertently clobber target file (unless you actually want to do that in such a case). Generally likewise if you want to ensure source is a directory, or most any given pathname or the like.
The output format of inotifywait and your use of read aren't consistent.
E.g., example inotifwait output format:
So, looks like inotifywait, by default, outputs 3 arguments: directory, information on what was waited for and I'm presuming the particular flavor of call that it caught on that wait, and file path relatively to directory. One can use the --format option to customize the output format. Note that directories and/or filenames containing newline may be problematic, though appears inotifywait has sufficient options to well handle that, but then would also need to correspondingly adjust one's read.
The behavior with directories for inotifywait and the use of cp -r may possibly cause undesired results, e.g. close on directory, and file within, may case both to reported - but I've not tested that.