#bash

hackbyte@friendica.utzer.de

Now, for something completely different: (mid lenght post)

Years, actually decades ago, as i was a very young padawan, discovering and in tiny part shaping (a _VERY_ tiny part of) the early internet (world wide web way back then).

A unix guru gave his shine to me .. and told me a nice lesson, i never forgot, and with the help of the almighty internet relay chat (IRCNet) even was able to improve upon a tiny bit.

Way back then, you mainly had ps and top to list and manage your processes on a Unix based system.

Modern fancy stuff like killall didn't exist for a while, not to name pgrep even. (We're talking mid to late 90ies here).

So, this unix guru came over to me to tell me a nice trick for my linux boxes at home.. I won't repeat the original one, but will skip directly to the (just slighty) improved one;

It's a bash function called psg (procname)

psg () 
{
 /bin/ps xau | /bin/grep COMMAND\\\|$1 | /bin/grep -v grep
}

As you can imagine, psg stands for "ps grep". You can use it with the name of the process, the pid or even a part of its commandline to get exactly only processes listed which match your grep.

You don't need to remember any commandline parameters or anything at all (unlike pgrep) .. but just fire and forget, take what you get. (It's truly KISS-compliant;)

The "original version" i got told skipped the header from the ps command and just spat out the processes, but i liked to have the header preserved. So at some time i questioned people in #linux.de on IRCNet about how to improve the grep cmd(s) for that reason.

And here we are ... you're welcome to use psg anytime you want..... and preserve the lore! ;)

#Unix #Unices #Unixes #Linux #Retro #Retrocomputing #NextStep #Bash #Script #Lore #KISS #RandomShit ;)

P.s.: What i was shaping? Ouh shoot..... i was employed to write down early html (1.1) to implement the wet dreams of some few graphics designers from their macintosh with photoshop.... We didn't have frames .. but we had tables!! (yeah i know. ;))

paulkater@diasp.org

I created a tiny Bash script.
It checks $1, if empty then it exits

It jumps to my AppImage directory
Then:

./`ls -t1 $1*`

This is probably the fastest way to load the latest version of an app image identified in $1.

#Bash #AppImage

bkoehn@diaspora.koehn.com

TIL that #bash has variable references that you can use to get data from a function without a subshell. In other news, my semantic version sorter runs a full order of magnitude faster, but all of my tests fail from the refactoring.

z0n1n0z@diaspora-fr.org

ZigzagDownLoader logo di ZDL

DCC ...reverse!

Some XDCC BOTs shield server ports using "reverse DCC". In particular, https://xdcc.eu provides countless links to files in all languages ​​of the world via the host server irc.scenep2p.net, which uses "reverse dcc".
Unfortunately, there are few programs capable of downloading files through this type of protocol. For example, #weechat is not capable of performing this type of download.

From now, ZigzagDownLoader can download via reverse DCC!

#zdl #bash #linux #cygwin #downloader #axel #wget #aria2 #gnu #free #freesoftware #softwarelibero #zigzag #zigzagdownloader #condividetevelo #sharing #streaming #hosting #filehosting #xdcc #dcc #irc #automazione #dccreverse #reversedcc

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