#dash

harryhaller@diasp.eu

took me some hours (days) to realise it doh.
For those who use #dash and are faced with #bashisms:

bash: cat file | while read -d 'x' line ; do
dash: cat file | tr 'x' '\n' | while read line ; do

On the positive side, I can now drill down into horrible machine generated nested html like g-o-o-gle's translations of webpages - using dash. It all started with trying to parse RSS....
#gnu #linux #bash

prplcdclnw@diasp.eu

Interesting Trick with BASH

Also works with DASH

There is a way to get rid of the last, and only the last, newline in a file, if it exists. xxd, in case you don't use it often, reads stdin and shows you what was read, in hex.

printf "one\ntwo\nthree\n" > test.txt
cat test.txt | xxd
00000000: 6f6e 650a 7477 6f0a 7468 7265 650a       one.two.three.
printf "%s" "$(cat test.txt)" | xxd
00000000: 6f6e 650a 7477 6f0a 7468 7265 65         one.two.three

This won't work with DOS-style newlines (\r\n). The last \r won't be eliminated. That would need a tr -d "\r", but that would eliminate all the \rs.

If you knew for certain that there was a newline at the end, you could measure the length of the file with wc -c and use head -c to eliminate it. But this trick is so simple, I think I'd use it anyway with BASH and DASH.

I don't know if this trick works with any shells other than BASH and DASH. I think printf is always a built-in command, so it would depend on the shell.

BTW, DASH is the variant form of BASH that Debian and Debian derivatives use. With Mint, commands you type from the command line, by default, use BASH, but scripts, by default, use DASH. This matters because echo works slightly different with DASH and BASH. That's why some people use printf "%s\n" "whatever" instead of echo "whatever" in scripts.

#newline #newlines #bash #dash #shell #shell-script #trick #hack #programming #coding

jaywink@jasonrobinson.me

Going on a week long trip, travelling by land, with a few days of travel in sometimes poor network connectivity gave me a reason to check up on my offline docs setup. Zeal is an awesome #opensource offline docs browser based on the proprietary Dash documentation browser, supporting the same docsets. Updating the core docs is easy enough with a few clicks, but I wanted to also have the #Matrix spec with me fully offline. This was recently contributed by Christian Paul - but unfortunately Zeal lacks proper support for easily pulling in Dash user contributed docsets.

No fear, there is a handy CLI app to install user contributed Dash docsets called zeal-user-contrib. Just install, run and choose the docsets you want installed.

#programming #zeal #dash