I want to identify a string provided as an argument on command-line.I need to search only in just current directory and archives. my command is:
if grep -s "$1" * .*
then echo "found" else echo "not found"
But for example if i have one folder with the word "father" and another with "fathersa" and the string input is "father" my code output both folders.But if my input is "father "(father and space) the output should be only the first folder but my code display both folder.What should i do instead? Also is this command good enough to search through all folders and archives from my current directory? Edit: i`m using Ubuntu desktop (Ubuntu 12.04.4 LTS)
I also tried grep -w
but my string is not exactly a fixed string, its actually a pattern so it isnt really what i wanted.If my input is "fa" my code should output all folders that contains the "fa" structures like "father" "fat" and so on but if my input would be "fa " with space my output should be only the folders with "fa" and just that
./script.sh 'fa '
orfa\
else your space will get trimmed – May 06 '20 at 19:46if command; then command; else command; fi
– May 06 '20 at 20:45if grep -q -R "$1"; then echo ok; else echo fail; fi
as the answer says. – May 07 '20 at 09:30t see space as a string(pattern) because when i tried to input "father mother" it didn
t really work.My code is working with only one word,not more and i need to work for more and maybe thats why i don
t have the results i need – MIfi22 May 07 '20 at 09:51'(father|mother)'
And you need to add-E
option to grep – May 07 '20 at 10:06