Is it possible to write the script script.sh
, using BASH that
- The argument is a string of characters and the output is all possible words from these characters and The script searches for words in the file besede.txt in this case only two words
$script.sh jugrot
jogurt
rojgut
does somebody know what is wrong and why it doesn't want to add all permutations into a table
#!/bin/bash
permutation() {
array=()
local items="$1"
local out="$2"
local i
[[ "$items" == "" ]] && array[$i]+=$out && return
for (( i=0; i<${#items}; i++ )) ; do
permutation "${items:0:i}${items:i+1}" "$out${items:i:1}"
done
}
permutation $1
for i in "${array[$i]}"
do
echo "$i"
done