I am trying to write a script on a Debian Jessie host.
I am having an issue with trying to run the following command (with a twist) in a script:
find ~/* -path ~/FileSniper* \
-prune -o \
-type f \( -name "*.mp4" -o -name "*.sh" -or -name "*.mp3" \) \
! -name '*.txt' -printf "%f\n"
What I am trying to do in the script is make the user have to type in the file formats he/she wants to search for, after that, I pipe this to sed
, which will make sure it obtains the right format:
echo "Input the formats like this: \"mp3,mp4,exe,sh\""
read -p "input:" formats
formattedformats=`echo "-name \"*.""$formats""\"" | sed 's/,/" -o -name "*./g'`
find_parameters=(\(formattedformats\))
Here the $find_parameters
will contain something like:
-name "*.mp3" -o -name "*.mp4" -o -name "*.sh"
I can't figure out what is wrong with this line:
find ~/* -path ~/FileSniper* -prune -o -type f "${find_parameters[@]}" ! -name "*.txt" -printf "%f\n" > foundfiles.txt
I have researched what I could, but still haven't been able to figure out what is wrong. Please point me in the right direction.
~/*
? are you trying to exclude hidden.
directories? you could dofind ~ -not -path '*/.*' ...
instead.scriptname.sh mp3 mp4 exe sh