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:

743
active users

#unixshell

0 posts0 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?

I experimented with not having persistent shell history, after @simontatham blogged about it.

Good:
- higher threshold for writing long complicated commands
- lower threshold for writing shell scripts instead

Bad:
- writing shell scripts

I've since started experimenting with the Fish shell, and it brings a whole different level to the shell history game. So far I like it.

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

🛠️ Curious how coding can support your research?
Join our Software Carpentry Workshop for absolute beginners – no experience needed, just curiosity and motivation!

📅 May 12–13, 2025, 09:00–16:00
📍 ZB MED, Cologne
👩‍💻 Hands-on sessions on:
#UnixShell
#Git for version control
#Python programming

👩‍🏫 With @RabeaMue, Silvia Di Giorgio & Justine Vandendorpe
🔗 Register: zbmed.github.io/2025-05-12-Sof

Replied in thread

@jeeynet Salut, merci pour l'idée, je ne savais pas que c'était possible ! Concernant le script proposé, ce test est bizarre  :

if [ "${1}" ]

Si "${1}" venait à coïncider avec un opérateur de test(1) , vous auriez des surprises. Je suggère ceci à la place :

if [[ $# -gt 0 ]]

ou bien

if [[ -n "$1" ]]

Notes :

  • on peut se permettre [[ … ]] car le script utilise Bash;

  • vous pouvez enlever les " autour de $1 dans cet exemple mais attention, c'est un cas bien particulier dû au fait que [[ … ]] ne fait pas de “word splitting” sur l'expression fournie).

Replied in thread

@zigg

hier(7) on #FreeBSD et al. suggests /usr/local/libexec/${YOURAPP} .

The logical extension to the XDG Base Directory Specification would likewise be ${HOME}/.local/libexec .

Of course the . command follows $path , which won't include either of those.