Portal Home > Knowledgebase > Articles Database > How to make shell script ask input
How to make shell script ask input
Posted by slrslr, 08-15-2013, 06:26 AM |
Hello,
i always forget right syntax or im lazy to write commands like:
find . -type f -exec grep -i SEARCHPHRASSEHERE '{}' \; -print
so i would like to ask how to do shell script, which will upon execution ask me to enter search prasse.
like in command line i type: search. and it will run this script and ask me for search phrasse.
Or i will type search/ and it will run another script which will be searching whole filesystem.
how such script which will run such command and ask user to input search phrasse look like and how to execute it by typing special command from commandline from any directory?
|
Posted by Patrick, 08-15-2013, 07:30 AM |
Put this in a shell script:
|
Posted by RobertJP, 08-15-2013, 08:12 AM |
I think what he needs is a read input than execute like below.
#!/bin/bash
read -p "Type the search querry here:" querry;
find . -type f -exec grep -i $querry'{}' \; -print
|
Posted by slrslr, 08-20-2013, 06:01 AM |
Thanks, your script asks input, but it dont find anything, only empty line, runing for hour, but my input was "x" (without quotes) and i made sure in same folder is file which contains this letter.
|
Posted by foobic, 08-20-2013, 06:36 AM |
There's no need to use find -exec grep anyway - just use grep -r for a recursive search (or -lri if you like, to list only matching filenames with a case-insensitive search).
|
Add to Favourites Print this Article
Also Read