shakedown.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
A community for live music fans with roots in the jam scene. Shakedown Social is run by a team of volunteers (led by @clifff and @sethadam1) and funded by donations.

Administered by:

Server stats:

266
active users

#ShellScripting

2 posts2 participants0 posts today

In the helpful shell functions department:

(Requires bc to be installed)

load() {
    local load=$(uptime |sed -E "s/^.*load averages?: //; s/,.*$//")
    local uname="$(uname)"
    local cpus
    if [[ $1 == -q ]]; then
        echo "$load"
    elif [[ $1 == -i ]]; then
        echo "$load + 0.5" |bc -l |cut -f1 -d.
    else
        case "$uname" in
            Linux)  cpus=$(grep -c ^processor /proc/cpuinfo);;
            *BSD)   cpus=$(sysctl hw.ncpu |tr -dc "0-9\n");;
            *)      warn "load(): assuming 1 cpu, don't know how to get the number in \"$uname\""
                    cpus=1;;
        esac
        local loadPerCPU=$(echo "scale=3; $load / $cpus" |bc -l |sed 's/^\./0./')
        echo "$load ($loadPerCPU per processor ($cpus))"
    fi
}

#Poll: Curious about people's attitudes towards shell scripting.

Two part question:

  1. Are you a DEVeloper (or working in a development-heavy role), OTHER-IT worker (such as a sysadmin, architect, anything in a non-development-heavy role), or NON-IT (accountant, doctor, whatever)
  2. Do you HATE shell scripting, are you INDIFferent towards (or ignorant of) shell scripting, or do you LOVE it?

Liebe Folglinge,

ich suche leider noch immer nach einem neuen Job als #iOS und/oder #macOS Entwickler. Ich spreche #ObjectiveC, #Swift (auch Server-Side) und #SwiftUI und nutze die ganzen Tools drumherum (#Xcode, #Git, #GitHub, #GitHubActions, #ShellScripting etc.). Ich bringe 30 Jahre Berufserfahrung als Software-Entwickler mit, davon knapp 20 im #Apple Ökosystem.

Am Idealsten waere eine #Festanstellung zu 100% remote. Sollte es im Raum #Bregenz oder #Dornbirn etwas geben, dann auch gerne vor Ort.

Ich danke euch fuers Teilen. 🙏🏻
:boost_ok:

LinkedIn: linkedin.com/in/phranck/
Xing: xing.com/profile/Frank_Gregor0

New #blog post: Gathering Hashtags from the Fediverse

https://rldane.space/gathering-hashtags-from-the-fediverse.html

282 words (2233 counting the hashtags, but that's just silly)

cc: my wonderful #chorus: @joel @dm @sotolf @thedoctor @pixx @twizzay @orbitalmartian @adamsdesk @krafter @roguefoam @clayton @giantspacesquid

(I will happily add/remove you from the chorus upon request! :)

#100DaysToOffload #27

rldane.spaceGathering Hashtags from the Fediverse

Today I learned from the flock(1) man page (on Debian) that you can put this line at the top of a shell script to prevent more than one copy of it from ever running at a time:

[ "${FLOCKER}" != "$0" ] && exec env FLOCKER="$0" flock -en "$0" "$0" "$@" || :

This is an extremely clever hack and I don't know how I've never stumbled upon it in 38 years of writing shell scripts.
#unix #linux #scripting #shellScripting

I think I won't bother anymore with writing (bash) shell scripts that are longer than a few lines. I find the syntax too unintuitive and there are better programming languages like PHP that produce more readable code.

In the last two hours, I translated a bash shell script with ~250 lines to a PHP CLI script. The latter is nearly 400 lines long but definetly more readable and it also has more user-friendly output.

1/2

Interesting #ShellScripting quandary:

(solution below)

I'm uncertain how shells delimit filename variables internally.

I have a shell (bash) function that loops through a set of PDF files, opening them in zathura in a "suckless" tabbed window (so that the PDFs always open within the same window, so I can just hit q to zip through them one-at-a-time.

Here is my variable declaration:

local files=${*-*.[pP][dD][fF]}

But for simplicity, you could just imagine it to be:

files=*

Then I'm doing a

for f in $files; do

I'm wanting to print a status line for each item viewed, so I have an idea how many more there are to go, so I'm using this:

echo "[[$f]] ($count/$tot)"

And of course, there's a ((count++)) at the beginning of the loop.

But how to get the total ($tot)??

echo $files |wc -l will always result in 1, as does echo "$files" |wc -l

What I ended up doing was just creating a

for f in $files; do ((tot++)); done

One-liner loop before the actual loop, just to get a total.

Is there a better way?

Am I missing something really obvious?

Solution, courtesy of @khm

Use an array!

local files=(${*-*.[pP][dD][fF]})

echo "[[$f]] ($count/${#files[@]})"

Should've made this a long time ago:

function ciglob {
    #case-insensitive glob generator
    echo "$*" |while read -N1 c; do
        case "$c" in
            [a-zA-Z])   echo -n "[${c^^}${c,,}]";;
            *)          echo -n "$c"
        esac
    done
}
~ $ ciglob "Hello, world!"
[Hh][Ee][Ll][Ll][Oo], [Ww][Oo][Rr][Ll][Dd]!
~ $ ls -ld $(ciglob documents)
drwxr-xr-x 52 ~~~ ~~~ 20,480 Apr 10 11:45 Documents

(Not the most useful example, but I did have a use case in mind when I wrote it ;)

P.S. (This is a valid way to close a parenthesis. Fight me ;)

#bash#ksh#sh

Have any #Linux users tried this? It's called Swiss File Knife, and is a #FOSS utility available via Sourceforge.
It contains 100 command line utilities of various types.
It downloads to Linux as a single binary and is pretty easy to run and use so far.
Kind of fascinating, too, that it's cross-platform...
I haven't used it much but I'm wondering if it might be simpler than some similar Linux utilities.
Link: sourceforge.net/projects/swiss