0

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
rndint
  • 11
  • 2
  • Yes. It is possible. It could help, though, if you demonstrate how you've tried to solve this problem and where you hit a roadblock. – ctt May 05 '19 at 01:25
  • i know how to read file, but i don't know how to then check if they include all the characters and if the length is the same? – rndint May 05 '19 at 01:30
  • Well, dummy solution would be: create a list of all possible combinations of letters of the word and then grep for each combination inside the "besede.txt" word list. – KamilCuk May 05 '19 at 02:43
  • thanks mate i'll try, i'm really a total beginer at programing and at bash – rndint May 05 '19 at 02:54

0 Answers0