All I want to do is to search a directory of files for ANY part of a string. Here is the section of my code that processes this:
(input is set through user input)
input2=$(eval find . -name "$input" -print | sed -n 1p) #Using find to search for the file I need to read
... (Checking the file I 'found' actually exists)
out=$(eval $(shuf -n 1 "$input2")) #Shuffle it randomly
echo "$out" #Echo the output
If I had the file 'date' with the contents date "+%A %d %B %Y"
I could type 'date' and get the intended result but 'What is the date' would fail with
find: paths must precede expression: is
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
What is the easiest way to fix this problem?
edit
I haven't tried much as I am at a loss of what to do. I have tried wildcards in the search string but they don't work at all. Here is the entire input-to-output part of the source code:
while true; do
echo -n ">"
read input
input=${input,,}
echo "[DEBUG]: Recieved $input"
echo "[IO]: Accessing database"
input2=$(eval find . -name "$input" -print | sed -n 1p) || out="WARNING: Input/Output Error{TYPE=IO.GENERAL, VALUE=$input2}"
echo "[INPUT2]: Recieved $input2"
if [ ! -f "$input2" ]
then
input2="./db/unknowncommand"
fi
#out=$(<"db/$input") || out="WARNING: Input/Output ERROR" #Old 'just print whatever is in the file approach
out=$(eval $(shuf -n 1 "$input2")) || out="WARNING: Input/Output ERROR{TYPE=IO.GENERAL, VALUE=$input}" #Random output
echo "$out"
./JAISpeak "$out" #A small text-to-speech program I made
done