$ ./bla.sh 'y[es], n[o], v[iew], c[ancel], [al]l'
all|c|cancel|l|n|no|v|view|y|yes
Last active
December 15, 2015 08:39
-
-
Save mpapis/5232756 to your computer and use it in GitHub Desktop.
transform options to or string #bash
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 | |
| smth_checks() | |
| { | |
| typeset -a elements | |
| typeset IFS="," | |
| if [[ -n "${ZSH_VERSION:-}" ]] | |
| then elements=( ${=1// /} ) | |
| else elements=( ${1// /} ) | |
| fi | |
| for el in "${elements[@]}" | |
| do | |
| echo "${el//\[*\]/}" | |
| echo "${el//[\[\]]/}" | |
| done | sort -u | |
| } | |
| smth_check() | |
| { | |
| typeset IFS=$'\n' | |
| typeset -a elements | |
| elements=( $(cat -) ) | |
| IFS='|' | |
| __check="${elements[*]}" | |
| } | |
| smth() | |
| { | |
| typeset __check | |
| smth_check < <( smth_checks "$1" ) | |
| echo "${__check}" | |
| } | |
| smth "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment