7 ms·
Can you paste your bash one-liner here?
by maratc 4y ago
Can you paste your bash one-liner here?
- deleted 4y ago[deleted]
- deleted 4y ago[deleted]
- gabrielbarros 4y agooathtool --base32 --totp VHR2WYCQPNXIFB2SPLIAE2AZHQ
- remram 4y agoWhich part of this involves bash? This is an "oathtool one-liner" if anything.
- 22c 4y agoThe other "bash" one-liner references a bunch of tools that are not part of bash or even a POSIX environment. FWIW I would rather use oathtool than the other monstrosity.
- jsjohnst 4y ago> The other "bash" one-liner references a bunch of tools that are not part of bash or even a POSIX environment. You 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.
- remram 4y ago> You 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? 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>
- maratc 4y ago@jsjohnst is talking about his one-liner[0] that has lots of bash syntax, not the GP's one-liner[1] that only calls some external program. [0]: https://news.ycombinator.com/item?id=33254917 https://news.ycombinator.com/item?id=33254917 [1]: https://news.ycombinator.com/item?id=33249562 https://news.ycombinator.com/item?id=33249562
- jsjohnst 4y agoI had decided to back away, so thank you for pointing that out! There’s not just Bash syntax in mine, but rather advanced Bash that many terminal users wouldn’t recognize, so I was confused wth GP was on about until you pointed out he was probably referring to the other post which seemingly was trolling.
- jsjohnst 4y ago> We both disagree with you. What would that definition be? 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.
- jsjohnst 4y agoTo be very clear, I don’t use this, but I confirmed it does work and generates the same codes as the linked article. Requires Bash (3+) and doesn’t work as written in Zsh. https://gist.github.com/jsjohnst/95f34bc1f6ab46fd5c038138f0e9bfaf 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"