Skip to content

Instantly share code, notes, and snippets.

@remino
Created May 20, 2016 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remino/c7ca952e6b18b581f5cab1721eb28d76 to your computer and use it in GitHub Desktop.
Save remino/c7ca952e6b18b581f5cab1721eb28d76 to your computer and use it in GitHub Desktop.
wsort: Sort a single line of words
#!/bin/sh
# wsort
# Sort a single line of words
#
# Usage:
# wsort [words...]
# echo words | wsort
#
# Examples:
# wsort grape coconut apple
# => apple coconut grape
# echo foo bar | wsort
# => bar foo
# echo tokyo | wsort montreal
# => montreal tokyo
wsort() {
read WORDS
WORDS="$WORDS $@"
echo $WORDS | xargs -n1 | sort | xargs
}
wsort $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment