mastodon.xyz is one of the many independent Mastodon servers you can use to participate in the fediverse.
A Mastodon instance, open to everyone, but mainly English and French speaking.

Administered by:

Server stats:

811
active users

#shellscript

2 posts2 participants0 posts today
Replied in thread

@NOISEBOB #HowTo run #ShellScript when sound in mic

Here is a #bash function "getvol" which uses #SoX to listen for 0.1 second and then tells you peak volume, between 0 and 1:

function getvol {
rec -p trim 0 .1 stat 2>&1 >/dev/null | grep -Po "(?<=Maximum amplitude:).*" | grep -Po "\S+"
}

You can loop the function and do something if the volume is high enough.

Replied in thread
Just as a tip, if you want to write portable #shellscript, stick to the #POSIX #shell: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sh.html – all the tools you can use are also documented, like e.g. sed: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html

This POSIX shell is more or less a #bourne shell, but specifies a few more features than the classic bourne shell had, e.g. usage of $( ... ) for command replacement instead of only backticks. #FreeBSD's /bin/sh is (AFAIK) POSIX compliant, but I'd assume even this shell can do a few things not specified in POSIX. For testing, I found shells/bosh very useful, it contains a few flavors of minimal shells, one of them a POSIX shell.

Regarding specifically arrays, indeed, the POSIX sh doesn't know them with the single exception of the "argv" array (both for the main script and any shell function), which you can also modify using set, but that of course has other implications. What's always available is word splitting, any variable can contain a list separated by whatever $IFS is set to. It defaults to whitespace. You may override $IFS, but that can be tricky as well, word splitting is used a lot, so expect surprising effects. 🙈

Most of the time, it's best to find a way to solve your problem without arrays. 😉
pubs.opengroup.orgsh

Today in "this should not have been a #ShellScript": github.com/DrHyde/shellscripts

The #shenanigans around the invocation of #iconv are for portability (some versions of it DIE if you silence STDOUT the normal way by redirecting it to /dev/null) and then once it was a three line script I thought "wouldn't it be nice if it took arguments, and had doco, and handled errors", and at no point was solving the next little problem enough to make me re-write it in a better language, and then ... 1/2

GitHubshellscripts/check-encoding at master · DrHyde/shellscriptsRandom shell stuff. Contribute to DrHyde/shellscripts development by creating an account on GitHub.

Learning about making and creating and checking checksums in bash scripts to compare files.

Have always loved bash scripting… I am *sure* there is a much more elegant way to do this, but it's a start.

I love the very direct impacts of scripting things... 'make it do this'.... and computer dutifully complies. Including when you unintentionally tell it to do something stupid/destructive. lol.

Interesting coding idea for a nice afternoon while waiting for things to reboot, inspired by a post by @starlabssystems

https://codeberg.org/pswilde/FediFollowyCounty

Gets your current follower count, and sticks it in a csv file you can then use in... well... anything you like, #Grafana for example, or #PowerBI (ha) to track follower changes over time

Codeberg.orgFediFollowyCountya quick bash script to get your current fediverse follower numbers and write to a csv file