Skip to content

Instantly share code, notes, and snippets.

IFS=: read -ra paths <<<"$PATH"; eval "printf '<%s> ' find / \( -type d \( $(printf -- '-name %q -o ' "${paths[@]::${#paths[@]} - 1}") -name \"\${paths[-1]}\" \) \) -prune -o \( -type f -executable -print -quit \)" )
@ormaaj
ormaaj / compgen --man
Created August 6, 2015 05:59
ksh completion
NAME
compgen - command completion.
SYNOPSIS
compgen [ options ] [word ...]
DESCRIPTION
Specify how arguments to each name should be completed. If the -p option is
supplied, or if no options are supplied, existing completion specifications
are printed to standard output in a way that allows them to be reused as
@ormaaj
ormaaj / gist:d8ed8e3acab0412af41c
Created September 9, 2015 08:51
mono 4.3.x configure --help
`configure' configures mono 4.3.0 to adapt to many kinds of systems.
Usage: ./configure [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
Configuration:
$ ( for sh in ksh mksh zsh bash; do "$sh" /dev/fd/3; done ) 3<<\EOF
${ZSH_VERSION+'false'} || emulate ksh
${BASH_VERSION+shopt -s expand_aliases}
${KSH_VERSION+\:} alias integer=typeset
[[ ${!KSH_VERSION} == .sh.version ]] || alias .=
function f {
${1+'false'} || integer depth=$1 iter=$2
if ((!depth--)); then
integer i=$iter
$ doc/projects/bash/testcases/pattest.py
bash dash ksh mksh zsh bb posh jsh
x=\\; case \\x in "${x}""${x}"x) :;; *) false; esac 1 1 1 1 1 1 1 1
x=\\; case \\x in "${x}"${x}x) :;; *) false; esac 0 0 1 1 1 1 1 1
x=\\; case \\x in "${x}""\\"x) :;; *) false; esac 1 1 1 1 1 1 1 1
x=\\; case \\x in "${x}"\\x) :;; *) false; esac 1 1 1 1 1 1 1 1
x=\\; case \\x in ${x}"${x}"x) :;; *) false; esac 1 0 1 1 1 1 1 1
x=\\; case \\x in ${x}${x}x) :;; *) false; esac 0 0 1 1 1 1 1 1
x=\\; case \\x in ${x}"\\"x) :;; *) false; esac 1 0 1 1 1 1 1 1
x=\\; case \\x in ${x}\\x) :;; *) false; esac 1 0 1 1 1 1 1 1
@ormaaj
ormaaj / gist:1141086
Created August 11, 2011 23:38
Cut a glob from both ends of a string in one command without storing an intermediary value.
#!/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)}"
@ormaaj
ormaaj / input
Created August 24, 2011 23:21
Close but not quite
[Background]
Bold=false
Color=0,0,0
[BackgroundIntense]
Bold=false
Color=104,104,104
[Color0]
Bold=false
@ormaaj
ormaaj / out
Created October 1, 2011 08:46
Some testcases for concurrent background jobs and pipe I/O
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
@ormaaj
ormaaj / exbug
Created January 23, 2012 07:29
Bash parsing of redirects on exported functions
#!/usr/bin/env bash
set -x
f() {
echo 'hi'
} >&${1}
{ f 3; cat; } <<<'' 3>/dev/stdin
@ormaaj
ormaaj / gist:2147018
Created March 21, 2012 13:47
Reverse
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');