summarylogtreecommitdiffstats
path: root/script.sh
blob: 90f86033bb56397a26205d32f18f8cb9125b6887 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash


userInput='';

if [[ -z $1 ]];then
	read -p "Please Enter the word that you're looking for : " word
else 
	userInput=$1
fi

firstLetter=$(echo $userInput | cut -c 1 | tr a-z A-Z)
file="/etc/farsidic/dictionaries/${firstLetter}.json";

word=$(jq ".Words[] | select(.EnglishWord == \"${userInput}\")" $file)
isWordExisted=$(echo $word | jq 'length')



if [[ $isWordExisted -eq 0 ]];then
	echo 'The word' $userInput 'not found'
	exit
fi;


length=$( echo $word | jq '.Meanings | length')



result=$(echo $word | jq '.Meanings')


for i in $(seq 0 $(($length - 1)) );do
	echo $result | jq ".[${i}]"
done