From Newsgroup: comp.unix.shell
In article <10893ja$1dihv$
1@dont-email.me>,
Lawrence DOliveiro <
ldo@nz.invalid> wrote:
I was trying to write a Bash script to clean up the old checkpoints in
my Jupyter notebooks directories, which have been accumulating for
some years. The first version looked like this:
...
but it didnt work. I figured out that the BASEDIR and CHECKPOINTSDIR >variables were not being properly expanded inside the coproc command.
If I substitute those values literally
coproc collector { find ~/Documents/Jupyter\ Notebooks/ -type d -name
.ipynb_checkpoints -print0; }
then it works.
How would I pass variables into that coproc command?
First, I think you should switch to using "mapfile" instead of "coproc/read". "mapfile" is extremely good for this sort of thing and I tend to use it in
all my scripts. In fact, the main script that I've been developing for
almost 5 years now, uses "coproc" at its core because when I first started, "coproc" looked interesting - and I hadn't really gotten used to "mapfile"
at that point. Not likely to go back and change it at this point, but,
looking back on it, I think if I had it to do all over again, I wouldn't
use "coproc" at all.
Try:
mapfile -t < <(find "$BASEDIR" -type d -name "$CHECKPOINTSDIR")
Note: This will fail if you have directory names with newlines in them, but then again, if you have directory names with newlines, you're in pretty bad straits already...
Second, my first reaction to your problem was that you need to export the variables (if you think it through, that kinda makes sense), but I just did
the following little test and it did the right thing:
$ foo=bar
$ coproc { echo "$foo"; }; read -u$COPROC; echo $REPLY
bar
$
So, I don't know...
--
What can you do with this besides printing sarcastic and obscene messages to the
screens of lusers at login or logout?
From the man page for "strfile(1)".
--- Synchronet 3.21a-Linux NewsLink 1.2