View gist:1141086
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
shopt -s extglob | |
a='aaabbbbccccc' | |
# Could be half this length if string assignment in an arithmetic context worked, or if the "foo" in ${#foo} could be any expression rather than a parameter. | |
echo "${a:b=$(b=${a%${a##*(a)}}; echo ${#b}),b:$(c=${a%%*(c)}; echo ${#c})-b}" | |
# Equivalent to any of: | |
# tmp="${a##*(a)}"; echo "${tmp%%*(c)}" |
View input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Background] | |
Bold=false | |
Color=0,0,0 | |
[BackgroundIntense] | |
Bold=false | |
Color=104,104,104 | |
[Color0] | |
Bold=false |
View out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a: 1 2 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1=16 2=14 | |
b: 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 2 1 2 1 2 1 2 1 2 1 2 1 2 1=14 2=16 | |
c: 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1=15 2=15 | |
d: 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 1 2 1 2 1 1 2 1 2 1 1 2 1 1=18 2=12 | |
e: 3 2 3 2 3 2 3 2 3 2 3 2 3 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 3 2 2=14 3=16 | |
f: 2 2 1 2 1 2 1 2 1 2 2 1 2 1 2 1 1 2 1 2 1 2 2 1 2 1 2 1 2 1 1=14 2=16 |
View exbug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -x | |
f() { | |
echo 'hi' | |
} >&${1} | |
{ f 3; cat; } <<<'' 3>/dev/stdin |
View gist:2147018
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reverse() { | |
set -- "$@" "${2}[*]" | |
local -a 'keys=("${!'"$1"'[@]}")' | |
local -a "$2"=$'([${keys[n++]}]\'="${'"$1"$'[keys[\'{'$((${#keys[@]}-1))$'..0}\']]}"\')' # Generate elements | |
local -a "$2"=$'(\''"${!3}"$'\')' #Concatenate elements | |
local -a "$2"'=('"${!3}"')' #Build array | |
declare -p "$1" "$2"; | |
} | |
fromArr=(4 [2]=3 5 6 [11]='9 10' 14 [15]=$'15[ -6'); |
View envtest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
unset -v x y sh | |
while IFS= read -r s; do | |
IFS= declare -a "shells=( $s )" | |
IFS= read -r testCase | |
printf '%s\n%6s%s\n' "$testCase" '' 'x y x y' | |
for sh in "${shells[@]}"; do | |
printf '%-4s: %s\n' "$sh" "$("$sh" -c "$testCase")" |
View mandelbrot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ksh | |
# Charles Cooke's 16-color Mandelbrot | |
# http://earth.gkhs.net/ccooke/shell.html | |
# Combined Bash/ksh93 flavors by Dan Douglas (ormaaj) | |
function doBash { | |
typeset P Q X Y a b c i v x y | |
for ((P=10**8,Q=P/100,X=320*Q/cols,Y=210*Q/lines,y=-105*Q,v=-220*Q,x=v;y<105*Q;x=v,y+=Y)); do | |
for ((;x<P;a=b=i=c=0,x+=X)); do |
View multiproc.bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [[ ${!KSH_VERSION} == .sh.version ]]; then | |
if builtin getconf; builtin pids; then | |
function BASHPID.get { .sh.value=$(pids -f '%(pid)d'); } | |
elif [[ -r /proc/self/stat ]]; then | |
function BASHPID.get { read -r .sh.value _ </proc/self/stat; } | |
else | |
function BASHPID.get { .sh.value=$(exec sh -c 'echo $PPID'); } | |
fi 2>/dev/null |
View rndstr.bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Print or assign a random alphanumeric string of a given length. | |
# rndstr len [ var ] | |
function rndstr { | |
if [[ $FUNCNAME == "${FUNCNAME[1]}" ]]; then | |
unset -v a l | |
printf "$@" | |
elif [[ $1 != +([[:digit:]]) ]]; then | |
return 1 | |
elif (( ! $1 )); then | |
return |
View mtimes.bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mtimes { | |
typeset x= | |
typeset -i n=0 | |
for x; do | |
n=0 | |
if [[ -d $x ]]; then | |
mtimes "$x"/* | |
else | |
while [[ ${arr[n]+$x} -ot ${arr[n]} ]]; do | |
((n++)) |
OlderNewer