I love this idea - “What is in your bin directory?” was one of my first Lobsters posts. https://lobste.rs/s/f4konf/ask_lobsters_what_s_in_your_personal_bin_directory
sponge: soak up standard input and write to a file
Ermmm, how it is different from >?
Try running the example on the page using > instead of sponge.
Edit: don’t do it on /etc/passwd.
I honestly see no difference…
The behavior you see depends on the shell. On bash 3.2 for an example:
$ cat foo
$ cat foo | tr o O >foo
$ cat foo
One thing that is different is that it’s explicitly not a shell construct, independent of bash, etc. Which means you can then do command | sed | sudo sponge /etc/file. Trying to redirect the output using > would fail with a permission denied (unless your user could actually write to /etc, like root).
command | sed | sudo sponge /etc/file
You can hijack tee for this purpose (pipeline | sudo tee /…/file > /dev/null), but buffering stdin before writing is extremely useful. Is sponge smart enough to buffer to another file and mv it into place at the end, I wonder?
pipeline | sudo tee /…/file > /dev/null
Yes. See the sponge manpage.
I find myself often needing a realpath (1) in a shell script when all I get from the standard is a realpath (3), so I carry this around with me.
are there are good,quick,small scripts to create summary statistics and histograms for numbers? numutils is mentioned in the description of moreutils, but it doesnt appear to provide those.
atchange is a handy script to trigger a command whenever a file gets updated. I use it to automate the edit-save-run loop when writing code. It’s not technically in my /bin directory, it’s in .bash_aliases as a shell script, which I wrote after reading about the original perl script described here
# atchange $1 $2
# runs command $2 whenever file $1 is modified
if [ "$#" -lt 2 ]
echo "Insufficient arguments. Requires at least 2"
echo "Usage: atchange [filename] [command(s)]"
while [ -f "$FILE" ] || ! echo "File $FILE not found"
#inotifywait -qq -e modify "$FILE"; # disabled to remove dependency. use polling instead
newmodtime=`stat -c %y "$FILE"`
if [ -z "$oldmodtime" ]; then
if [ "$newmodtime" != "$oldmodtime" ]; then
echo "*** atchange: $FILE change detected ($newmodtime) ***"
sleep 1 # may not be necessary
sleep 2 # polling interval