Skip to content

Instantly share code, notes, and snippets.

@mpapis
Last active December 15, 2015 08:39
Show Gist options
  • Select an option

  • Save mpapis/5232756 to your computer and use it in GitHub Desktop.

Select an option

Save mpapis/5232756 to your computer and use it in GitHub Desktop.
transform options to or string #bash
$ ./bla.sh 'y[es], n[o], v[iew], c[ancel], [al]l'
all|c|cancel|l|n|no|v|view|y|yes
#!/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