Skip to content

Instantly share code, notes, and snippets.

View jmarcher's full-sized avatar
💭
I may be slow to respond.

Joaquín Marcher jmarcher

💭
I may be slow to respond.
View GitHub Profile
#!/bin/bash
function divider() {
local _d=${3:-2}
local _n=0000000000
_n=${_n:0:$_d}
local _r=$(($1$_n/$2))
_r=${_r:0:-$_d}.${_r: -$_d}
echo $_r
}
@jmarcher
jmarcher / asserts.sh
Last active May 13, 2022 08:29
Experimenting with bash scripts
#! /bin/sh
# asserts if the correct number of parameters where passed to the function
# first parameter should always be $# which is the original count of parameters
# of the function
# second parameter is the correct number of parameters
# the last parameter is the name of the function which can be hardcoded or ${FUNCNAME[0]} can be used
function assert_argument_count() {
if [ $1 -ne $2 ]; then
echo "Illegal number of parameters '$3' passed $# but $2 needed" >&2

Keybase proof

I hereby claim:

  • I am jmarcher on github.
  • I am jmarcher (https://keybase.io/jmarcher) on keybase.
  • I have a public key whose fingerprint is 8693 7FDA 4FBF 6728 6182 4963 F61F B032 65DC CBF2

To claim this, I am signing this object: