lang/bash/ RandomScripts
I have a few trivial programs: exists
, allexist
and filterstat
(the latter because it is equivalent to files = filter(stat,glob("*"))
and similar – it does not pass through unmatched wildcard names, unlike normal glob wildcard expansion. See below.
Waiting for things
Downloads
Waiting for Chrome downloads to finish (though will stall if a download is interrupted and the .crdownload
is not removed.
while exists *.crdownload; do echo -ne "Waiting: $(date)\r"; sleep 1; done; echo
the echo -ne
and echo
at the end are only so that the text in the console changes so you know something's happenning.
Processes and Jobs
These are two Python scripts, lwn
(launch with name
exists, allexist and filterstat
Perl makes such programs very short to write due to things like the assumed $_
in things like for(@ARGV)
which is equivalent to for $_(@ARGV)
and basically is equivalent to e.g. for $_ in @ARGV
in a language like Python.
exists
Returns true provided at least one of its arguments exists
#!/usr/bin/env perl
for(@ARGV) { exit(0) if -e; }
exit(1)
allexist
Returns true unless at least one of its arguments does not exist. (Note: it returns true if given no arguments, whereas exists
returns false with no arguments.)
#!/usr/bin/env perl
for(@ARGV) { exit(1) unless -e ; }
exit(0);
filterstat
Returns arguments if and only if they exist (i.e. filters out non-existent files)
#!/usr/bin/env perl
for(@ARGV) { print "$_\n" if -e; }