#!/bin/bash usage() { echo "usage: $0 string" echo "shows all permutations of a string" } # If we don't have any arguments, then show how to use this script if [ "$1" = "" ]; then echo "not enough arguments" usage exit 1 fi perm() { items="$1" out="$2" [[ "$items" == "" ]] && echo "$out" && return for (( i=0; i<${#items}; i++ )) ; do ( perm "${items:0:i}${items:i+1}" "$out${items:i:1}" ) done } perm "$1"