This file contains hidden or 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 | |
| function getElem { | |
| while | |
| ${!1+\:} return 1 | |
| typeset -a "__getElemArr=${!1}" | |
| set -- "__getElemArr${1#*]}" | |
| [[ $1 == *\[!(@]|\*]) ]] | |
| do : | |
| done |
This file contains hidden or 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
| public static T Clamp<T>(this T value, T min, T max, IComparer<T> comparer = null) { | |
| if (comparer.Equals(null)) | |
| comparer = Comparer<T>.Default; | |
| if (comparer.Compare(value, min) <= 0) { | |
| return min; | |
| } else if (comparer.Compare(value, max) >= 0) { | |
| return max; | |
| } else { | |
| return value; |
This file contains hidden or 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
| foo=666 | |
| { eval "$(</dev/fd/4)"; } 3<<EOF1 4<<EOF2 | |
| var=$(printf %q "$foo") | |
| EOF1 | |
| $(</dev/fd/3) | |
| echo "$var" | |
| EOF2 |
This file contains hidden or 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
| _jshon() { | |
| shopt -s lastpipe | |
| { tee /dev/fd/3 | jshon "$@" >&4; } 3>&1 | | |
| input=$(</dev/fd/0) | |
| ((PIPESTATUS)) || echo "$input" | |
| } 4>&1 |
This file contains hidden or 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
| _jshon() { | |
| shopt -s lastpipe | |
| typeset input status | |
| { tee /dev/fd/3 | jshon "$@" >&4; } 3>&1 | |
| input=$(</dev/fd/0) | |
| ((PIPESTATUS[0])) && printf %s "$input" >&2 | |
| return "${PIPESTATUS[0]}" | |
| } 4>&1 |
This file contains hidden or 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
| 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 \)" ) |
This file contains hidden or 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
| To hopefully add some insight, here's briefly my understanding of how | |
| namerefs are supposed to work in these cases given the 3 implementations | |
| I'm aware of. | |
| Between ksh93, bash, and mksh, there are 3 different types of namerefs. | |
| All three support "dynamic" namerefs, where each time a variable is | |
| referenced, the shell looks at the currently visible variable whose name | |
| is pointed to by the reference. All namerefs in bash and mksh are of | |
| this type. |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| # Try hard to set HOME and USER correctly. | |
| # Supply a list of methods and try them until one is successful | |
| function forceEnv { | |
| typeset -A methods | |
| until | |
| case ${1+_}${1-unset} in | |
| ${methods[_$1]+*}) shift; continue ;; | |
| unset) echo 'None of the supplied methods were successful.' >&2; return 1 ;; | |
| _getent) getent passwd "${EUID:-$(id -u)}" | IFS=: read -r USER HOME{,,,,} SHELL ;; | |
| _logname) USER=$(logname) && eval "HOME=~${USER}" ;; |
This file contains hidden or 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
| `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: |