`mintotp.totp('ZYTYYE5FOAGW5ML7LRWUL4WTZLNJAMZS')`
oathtool --base32 --totp VHR2WYCQPNXIFB2SPLIAE2AZHQYou do understand that there is a commonly accepted definition of a bash one-liner and that the one I shared fits that definition spot on, right? Further, there is a bunch of very Bash specific code in it that doesn't work in most other Posix compliant shells, so your scare quotes feel even more like a failed trolling attempt.
> FWIW I would rather use oathtool than the other monstrosity.
So would any sane person. The point wasn't what you should use, it was what is possible, which if you had read comments up the thread chain and tried to understand the context rather than making it a pissing contest about which tool is better when that wasn't even the question at hand.
We both disagree with you. What would that definition be?
The one-liner in question doesn't have any of bash's syntax in it. You could pass those words to execve() directly, without any shell, and it would still work. Calling it a line of bash code is just wrong.
Similarly, would you say this is a PHP one-liner? You can run it through PHP, but it contains no PHP syntax:
<h1>My web page</h1>A “bash one-liner” as in common use is a chain of commands using any combination of pipes, subshells, variables, tests, loops, etc.
The distinction between a “bash one-liner” and a “bash script” is that extraneous white space is removed and generally speaking should still be readable.
Admittedly mine is pushing the limits of readability do to the advanced bash syntax, but I still feel it qualifies.
Also, just because my reply was threaded two levels below yours doesn’t mean I was replying to you. I had upvoted you in fact as I actually agree with you re: oathtool example. The party I was replying to actually doesn’t agree with you and thinks that the oathtool example is a “bash one-liner” and that because I call other basic Unix commands mines not, which is just silliness.
What I take issue with is the arbitrary point made by the post I replied to that using oathtool is somehow not "bash one-liney", whereas your attempt is somehow "bash one-liney".
Could I make a bash one-liner that uses a rube goldberg machine of echo, netcat, dd, ed etc. to make a HTTP request? Yeah I could, or I could just use curl and it's also still a valid "bash" one-liner.
Can you paste your bash one-liner here?
As previously, I’m interested in seeing your Rube Goldberg machine, and mainly for adoration, not practical use. `curl`, as previously, would not qualify.
Add in few useless pipes to cat and dd, and you got yourself a Rube Goldberg machine.
For GP, the reason this is an HTTP/0.9 request is because it doesn’t specify a version number on the GET line (HTTP/1.0 would require that to be “GET / HTTP/1.0\r\n\r\n”). HTTP/0.9 was the “one-line” version of HTTP before headers and such were added. Not sure if @22c intended the pun there, but if so, we’ll played!
`curl | awk …` is a “shell one-liner” (albeit very basic)
Throw in some $(()), ${var:##}, etc and it’s a great example of a “bash one-liner”
https://gist.github.com/jsjohnst/95f34bc1f6ab46fd5c038138f0e...
————
read -r -p 'Secret Key: ' secret_key; dgst=$(printf '%016X' $(($(date -u '+%s') / ${TOTP_PERIOD_SECONDS:=30})) | xxd -r -p | openssl dgst -sha1 -mac hmac -macopt "hexkey:$(printf $secret_key | tr '[:lower:]' '[:upper:]' | base32 -d | xxd -p)"); offset=$(( 2 * 16#${dgst: -1} )); token=$(( ( 16#${dgst:offset:8} & 0x7fffffff ) % 10**${TOTP_DIGITS:=6} )); printf "%0${TOTP_DIGITS}d\n" "$token"That said, TOTP shouldn’t be treated as code golf, especially in production code. The point is the protocol is trivially simple to implement not that it’s X lines in Y language.
Except for the final reduction, which in the RFC is implemented via a mod, and the base32 decoding, which is not part of either HOTP or TOTP RFCs, but is instead part of the ad hoc "key uri" format. Which is a funny spec because it was defined for Google Authenticator yet AFAIK GA uses none of the parametrisation so that's only useful if you specifically want to exclude GA users.