Show HN: now.sh
github.com
github.com
If you don't know about moreutils check out the collection. I don't know what I'd do without vipe or vidir:
Chronic: runs a command quietly unless it fails
combine: combine the lines in two files using boolean operations
ifdata: get network interface info without parsing ifconfi
ifne: run a program if the standard input is not empty
isutf8: check if a file or standard input is utf-8
lckdo: execute a program with a lock held
mispipe: pipe two commands, returning the exit status of
parallel: run multiple jobs at once
pee: tee standard input to pipes
sponge: soak up standard input and write to a file
ts: timestamp standard input
vidir: edit a directory in your text editor
vipe: insert a text editor into a pipe
zrun: automatically uncompress arguments to command
[1] http://joeyh.name/code/moreutils/now is different. It re-prints current time once a second while waiting for the input. You basically get the running clock at the last line of output.
> ifdata: get network interface info without parsing ifconfi
If it's Linux, ifconfig isn't maintained anymore and might actually be lying (eg, virtual IPs on vlans on bonded NICs - sounds exotic but almost every trading house uses this config). Use the 'ip' command for most things you would have done with 'ifconfig'.
If it's BSD, ignore that and ifconfig away.
It's about as bad as Solaris with their ifconfig/ipadm stuff and changing everything around so that configuration exists in multiple places and one tool doesn't handle the other. ipadm doesn't properly deal with /etc/<hostname>.<interface> files and the two will conflict. Ugh.
Whoa! No kidding? I wrote a program years ago, probably around 2005, also called sponge, that does exactly this[1].
I'm not sure how to feel about this. Obviously the idea was a good one, but it's equally obvious I suck at getting the word out about my creations.
[1] https://github.com/graue/graue-utils/blob/master/sponge.c
That can be said for so many of these programs.
cat <<EOF > output.txt
some
input
EOFjoeyh's example:
sed "s/root/toor/" /etc/passwd | grep -v joey | sponge /etc/passwd
My example: sort <foo | sponge fooIf the pipe is an unfulfilled promise (no concurrency) then there's no problem. But if the pipe does what it's designed to do, you will lose the file.
EDIT -- after tinkering around with the console, I see. I'm wiping the file out by writing to it (>) before it's finished reading (<). Neat, TIL!
whatever <file | tee file 1>/dev/null
1. I never thought to try that. How silly of me. OR
2. Perhaps tee behaves differently on OpenBSD (which I was using at the time).
EDIT: this doesn't work for the "sed s/foo/bar/ file|sponge file" case, but it does for certain other usages where you basically want to wait until EOF before outputting
[start time] $ ./run_long_script
[ end time ] $
My actual prompt looks like: [09:36] bmd-mba|bmd ~
$ whoami
bmd
[09:36] bmd-mba|bmd ~
$
Details in https://github.com/coderholic/config/blob/master/.bash_profi...It also colour codes the output and allows you to tail multiple files simultaneously.
1) Really? This is on the front page of HN?
2) why aren't you printing to stderr?
(No idea why not stderr however)
2) Ah, pedantic nitpicking, love it. Because the script is meant for interactive use with no streams redirected off the terminal, and because it doesn't output diagnostics or errors, but rather augments the stdout.
Or put differently - show me an example where writing into stderr would make more sense.
(edit) I guess someone can tee the output afterwards. Fine, I'll make it use stderr.
e.g. echo "03/Mar/2013 01:16:52 +0000" | mytz => 02/Mar/2013 17:16:52 -0800
Sun Mar 3 10:05:17 PST 2013
The above converts to the system TZ. Or:
$ echo $( export TZ=CST; date -d "Sun Mar 3 18:05:17 UTC 2013" )
Sun Mar 3 18:05:17 CST 2013
The above converts from any TZ to any other TZ, without resetting your shell's TZ variable.
$ TZ=CST date -d "Sun Mar 3 18:05:17 UTC 2013"
Sun Mar 3 18:05:17 CST 2013
which doesn't invoke a subshell. env vars can always be prepended to the executable name for use with just that program (not sure if that's bash only, though).