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).
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?
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
function atchange(){
if [ "$#" -lt 2 ]
then
echo "Insufficient arguments. Requires at least 2"
echo "Usage: atchange [filename] [command(s)]"
else
FILE="$1"
shift
COMMAND="$@"
oldmodtime=""
while [ -f "$FILE" ] || ! echo "File $FILE not found"
do
#inotifywait -qq -e modify "$FILE"; # disabled to remove dependency. use polling instead
newmodtime=`stat -c %y "$FILE"`
if [ -z "$oldmodtime" ]; then
oldmodtime="$newmodtime"
fi
if [ "$newmodtime" != "$oldmodtime" ]; then
echo "*** atchange: $FILE change detected ($newmodtime) ***"
sleep 1 # may not be necessary
$COMMAND
oldmodtime="$newmodtime"
fi
sleep 2 # polling interval
done
fi
}
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:
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).You can hijack
teefor this purpose (pipeline | sudo tee /…/file > /dev/null), but buffering stdin before writing is extremely useful. Isspongesmart enough to buffer to another file andmvit into place at the end, I wonder?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
Perhaps spark.