#unixshell — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #unixshell, aggregated by home.social.
-
Wrote a #shell function without using
lsinside of$( ), so my inner @mirabilos won't harass me. XD#slightly easier wireguard command function wg { local dir file profile profiledir= parm=${1:-} statustext #Find profile dir for dir in {,/usr/local}/etc/wireguard; do if [[ -d $dir ]]; then profiledir=$dir break fi done #Find config file if [[ -n $profiledir ]]; then for file in $profiledir/*.conf; do if [[ -e $file ]]; then profile=${file//*\/} profile=${profile/.conf} break fi done fi [[ -n $profile ]] || profile=proton statustext="wireguard profile $profile" case ${parm,,} in up|on) doas wg-quick up $profile;; down|off) doas wg-quick down $profile;; status) echo -en "$statustext _______\r" echo -en "$statustext " ifconfig |grep -q "^$profile:" && echo enabled || echo disabled;; *) warn "wg usage: wg up|down|status";; esac }Hmm, seems
${foo,,}for lower case conversion is #bash-only. I wonder if I should usetrinstead. -
Wrote a #shell function without using
lsinside of$( ), so my inner @mirabilos won't harass me. XD#slightly easier wireguard command function wg { local dir file profile profiledir= parm=${1:-} statustext #Find profile dir for dir in {,/usr/local}/etc/wireguard; do if [[ -d $dir ]]; then profiledir=$dir break fi done #Find config file if [[ -n $profiledir ]]; then for file in $profiledir/*.conf; do if [[ -e $file ]]; then profile=${file//*\/} profile=${profile/.conf} break fi done fi [[ -n $profile ]] || profile=proton statustext="wireguard profile $profile" case ${parm,,} in up|on) doas wg-quick up $profile;; down|off) doas wg-quick down $profile;; status) echo -en "$statustext _______\r" echo -en "$statustext " ifconfig |grep -q "^$profile:" && echo enabled || echo disabled;; *) warn "wg usage: wg up|down|status";; esac }Hmm, seems
${foo,,}for lower case conversion is #bash-only. I wonder if I should usetrinstead. -
Wrote a #shell function without using
lsinside of$( ), so my inner @mirabilos won't harass me. XD#slightly easier wireguard command function wg { local dir file profile profiledir= parm=${1:-} statustext #Find profile dir for dir in {,/usr/local}/etc/wireguard; do if [[ -d $dir ]]; then profiledir=$dir break fi done #Find config file if [[ -n $profiledir ]]; then for file in $profiledir/*.conf; do if [[ -e $file ]]; then profile=${file//*\/} profile=${profile/.conf} break fi done fi [[ -n $profile ]] || profile=proton statustext="wireguard profile $profile" case ${parm,,} in up|on) doas wg-quick up $profile;; down|off) doas wg-quick down $profile;; status) echo -en "$statustext _______\r" echo -en "$statustext " ifconfig |grep -q "^$profile:" && echo enabled || echo disabled;; *) warn "wg usage: wg up|down|status";; esac }Hmm, seems
${foo,,}for lower case conversion is #bash-only. I wonder if I should usetrinstead. -
Wrote a #shell function without using
lsinside of$( ), so my inner @mirabilos won't harass me. XD#slightly easier wireguard command function wg { local dir file profile profiledir= parm=${1:-} statustext #Find profile dir for dir in {,/usr/local}/etc/wireguard; do if [[ -d $dir ]]; then profiledir=$dir break fi done #Find config file if [[ -n $profiledir ]]; then for file in $profiledir/*.conf; do if [[ -e $file ]]; then profile=${file//*\/} profile=${profile/.conf} break fi done fi [[ -n $profile ]] || profile=proton statustext="wireguard profile $profile" case ${parm,,} in up|on) doas wg-quick up $profile;; down|off) doas wg-quick down $profile;; status) echo -en "$statustext _______\r" echo -en "$statustext " ifconfig |grep -q "^$profile:" && echo enabled || echo disabled;; *) warn "wg usage: wg up|down|status";; esac }Hmm, seems
${foo,,}for lower case conversion is #bash-only. I wonder if I should usetrinstead. -
Wrote a #shell function without using
lsinside of$( ), so my inner @mirabilos won't harass me. XD#slightly easier wireguard command function wg { local dir file profile profiledir= parm=${1:-} statustext #Find profile dir for dir in {,/usr/local}/etc/wireguard; do if [[ -d $dir ]]; then profiledir=$dir break fi done #Find config file if [[ -n $profiledir ]]; then for file in $profiledir/*.conf; do if [[ -e $file ]]; then profile=${file//*\/} profile=${profile/.conf} break fi done fi [[ -n $profile ]] || profile=proton statustext="wireguard profile $profile" case ${parm,,} in up|on) doas wg-quick up $profile;; down|off) doas wg-quick down $profile;; status) echo -en "$statustext _______\r" echo -en "$statustext " ifconfig |grep -q "^$profile:" && echo enabled || echo disabled;; *) warn "wg usage: wg up|down|status";; esac }Hmm, seems
${foo,,}for lower case conversion is #bash-only. I wonder if I should usetrinstead. -
Recursion usually scares me a bit, but it worked out nicely here:
#convert "cx"-style Esperanto notation to native accents (ĉ) function eaccent { if [[ ${1:-} ]]; then echo "$*" |eaccent else sed 's/cx/ĉ/g; s/gx/ĝ/g; s/hx/ĥ/g; s/jx/ĵ/g; s/sx/ŝ/g; s/ux/ŭ/g; s/C[xX]/Ĉ/g; s/G[xX]/Ĝ/g; s/H[xX]/Ĥ/g; s/J[xX]/Ĵ/g; s/S[xX]/Ŝ/g; s/U[xX]/Ŭ/g' fi }#bash #unix #shell #scripts #scripting #UnixShell #ShellScripting #Esperanto
-
Recursion usually scares me a bit, but it worked out nicely here:
#convert "cx"-style Esperanto notation to native accents (ĉ) function eaccent { if [[ ${1:-} ]]; then echo "$*" |eaccent else sed 's/cx/ĉ/g; s/gx/ĝ/g; s/hx/ĥ/g; s/jx/ĵ/g; s/sx/ŝ/g; s/ux/ŭ/g; s/C[xX]/Ĉ/g; s/G[xX]/Ĝ/g; s/H[xX]/Ĥ/g; s/J[xX]/Ĵ/g; s/S[xX]/Ŝ/g; s/U[xX]/Ŭ/g' fi }#bash #unix #shell #scripts #scripting #UnixShell #ShellScripting #Esperanto
-
Recursion usually scares me a bit, but it worked out nicely here:
#convert "cx"-style Esperanto notation to native accents (ĉ) function eaccent { if [[ ${1:-} ]]; then echo "$*" |eaccent else sed 's/cx/ĉ/g; s/gx/ĝ/g; s/hx/ĥ/g; s/jx/ĵ/g; s/sx/ŝ/g; s/ux/ŭ/g; s/C[xX]/Ĉ/g; s/G[xX]/Ĝ/g; s/H[xX]/Ĥ/g; s/J[xX]/Ĵ/g; s/S[xX]/Ŝ/g; s/U[xX]/Ŭ/g' fi }#bash #unix #shell #scripts #scripting #UnixShell #ShellScripting #Esperanto
-
Recursion usually scares me a bit, but it worked out nicely here:
#convert "cx"-style Esperanto notation to native accents (ĉ) function eaccent { if [[ ${1:-} ]]; then echo "$*" |eaccent else sed 's/cx/ĉ/g; s/gx/ĝ/g; s/hx/ĥ/g; s/jx/ĵ/g; s/sx/ŝ/g; s/ux/ŭ/g; s/C[xX]/Ĉ/g; s/G[xX]/Ĝ/g; s/H[xX]/Ĥ/g; s/J[xX]/Ĵ/g; s/S[xX]/Ŝ/g; s/U[xX]/Ŭ/g' fi }#bash #unix #shell #scripts #scripting #UnixShell #ShellScripting #Esperanto
-
Recursion usually scares me a bit, but it worked out nicely here:
#convert "cx"-style Esperanto notation to native accents (ĉ) function eaccent { if [[ ${1:-} ]]; then echo "$*" |eaccent else sed 's/cx/ĉ/g; s/gx/ĝ/g; s/hx/ĥ/g; s/jx/ĵ/g; s/sx/ŝ/g; s/ux/ŭ/g; s/C[xX]/Ĉ/g; s/G[xX]/Ĝ/g; s/H[xX]/Ĥ/g; s/J[xX]/Ĵ/g; s/S[xX]/Ŝ/g; s/U[xX]/Ŭ/g' fi }#bash #unix #shell #scripts #scripting #UnixShell #ShellScripting #Esperanto
-
When you're dealing with plaintext data in a suspicious context, consider using `cat -v` where you'd usually use `cat`.
```
-v, --show-nonprinting
use ^ and M- notation, except for LFD and TAB
``` -
P.S., the body of the parent #toot was created by a simple #shell #function:
function apod { #Today's NASA Astronomy Picture of the Day info-fetcher curl -sL 'https://apod.nasa.gov/apod/archivepix.html' \ |grep -m1 "[0-9][0-9]:" \ |sed 's/^/Date: /; s|: *<a href="|\nURL: https://apod.nasa.gov/apod/|; s/">/\nTitle: /; s/<.*$//' echo echo "#NASA #Astronomy #PictureOfTheDay" }#bash #ksh #mksh #shellScripting #unix #UnixShell #WebScraping #Scraping #HTML
-
Rule/Yule 30 cellular automaton with a "band-pass" filter every few iterations. Done in the Bash shell using bitwise math, so each row/state is a single number of 63 bits.
#cellularautomata #cellularautomaton #rule30 #bitwiseoperators #textmode #textmodeart #oldskool #retrocomputing #unixshell #shellprogramming #xterm #joulu6 #xmastree #algorithmicart #algorist #mathart #laskutaide #ittaide #kuavataide #iterati
-
Rule/Yule 30 cellular automaton with a "band-pass" filter every few iterations. Done in the Bash shell using bitwise math, so each row/state is a single number of 63 bits.
#cellularautomata #cellularautomaton #rule30 #bitwiseoperators #textmode #textmodeart #oldskool #retrocomputing #unixshell #shellprogramming #xterm #joulu6 #xmastree #algorithmicart #algorist #mathart #laskutaide #ittaide #kuavataide #iterati
-
Rule/Yule 30 cellular automaton with a "band-pass" filter every few iterations. Done in the Bash shell using bitwise math, so each row/state is a single number of 63 bits.
#cellularautomata #cellularautomaton #rule30 #bitwiseoperators #textmode #textmodeart #oldskool #retrocomputing #unixshell #shellprogramming #xterm #joulu6 #xmastree #algorithmicart #algorist #mathart #laskutaide #ittaide #kuavataide #iterati
-
Rule/Yule 30 cellular automaton with a "band-pass" filter every few iterations. Done in the Bash shell using bitwise math, so each row/state is a single number of 63 bits.
#cellularautomata #cellularautomaton #rule30 #bitwiseoperators #textmode #textmodeart #oldskool #retrocomputing #unixshell #shellprogramming #xterm #joulu6 #xmastree #algorithmicart #algorist #mathart #laskutaide #ittaide #kuavataide #iterati
-
Rule/Yule 30 cellular automaton with a "band-pass" filter every few iterations. Done in the Bash shell using bitwise math, so each row/state is a single number of 63 bits.
#cellularautomata #cellularautomaton #rule30 #bitwiseoperators #textmode #textmodeart #oldskool #retrocomputing #unixshell #shellprogramming #xterm #joulu6 #xmastree #algorithmicart #algorist #mathart #laskutaide #ittaide #kuavataide #iterati
-
In the helpful shell functions department:
(Requires
bcto 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:
- 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)
- Do you HATE shell scripting, are you INDIFferent towards (or ignorant of) shell scripting, or do you LOVE it?
#Unix #UnixShell #ShellScript #ShellScripting #POSIX #PosixShell #sh #bash #zsh #csh #tcsh #ksh #pdksh #oksh #mksh
-
I've probably tooted about this before, but I don't know why this isn't standard.
It's just so obvious, at least to me. ;)
~ $ type mcd mcd is a function mcd () { [[ -n $1 ]] && mkdir "$1" && cd "$1" } -
A wild #blog post appears!
I do some benchmarking of #oksh with nine C compilers on #OpenBSD. Nothing conclusive is discovered, but it is nonetheless a very fun journey.
https://briancallahan.net/blog/20211010.html
#Unix #Linux #FreeBSD #NetBSD #DragonFlyBSD #BSD #C #compile #compiler #compilers #shell #unixshell #kornshell #ksh
-
I've released oksh-7.0 for all your shell needs.
#OpenBSD #FreeBSD #oksh #NetBSD #DragonFlyBSD #Unix #Linux #shell #ksh #KornShell #UnixShell