coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

date--date accept DATESTR from stdin?


From: Trey Blancher
Subject: date--date accept DATESTR from stdin?
Date: Tue, 1 Jun 2021 23:22:57 -0400

I ran across something that didn't work for me, but I see no reason why it shouldn't. I've tried this on a version of RHEL 7.6, as well as an up-to-date Arch Linux (coreutils 8.32). I have a script/command pipeline that extracts the password expiration date from `chage`, and I tried to feed it into `date`:

chage -l ${USER} | grep 'Password expires' | awk -F':' '{print $2}' | date -d - 
+%b-%d-%Y

But this didn't work, it just printed today's date. I guess this is because a bare dash/hyphen as a date specifier is ignored. I was able to workaround the problem by loading the `chage` call into a subshell:

date -d "$(chage -l ${USER} | grep 'Password expires' | awk -F':' '{print 
$2}')" +%b-%d-%Y

Reading the man/info pages for `date`, it doesn't look like -d/--date accepts the date DATESTR from standard input. It also doesn't look like a herestring will work, either. Other coreutils programs do accept a single hyphen
('-') to mean read from standard input, so that's why I figured it would work.

As i was writing this, I saw the -f/--file option, which does allow the dash/hyphen to mean read from standard input. Here's what just worked for me:

chage -l ${USER} | grep 'Password expires' | awk -F':' '{print $2}' | date -f - 
+%b-%d-%Y

Is that the answer? Would it even make sense to read -d/--date from stdin, knowing that -f/--file can do it?

I could see accepting the format from standard input as well, but I don't have a use case for it right now.

Trey Blancher
trey@blancher.net




reply via email to

[Prev in Thread] Current Thread [Next in Thread]