I have a bash script called findme
, which is coded as follows:
#!/bin/bash
locate -Abi '*\.'$1 $2 | grep --color=always -ni $2 | less -R
It searches for me for all files with a specified file extension (first argument provided to the script) which has a pattern (the next provided argument) in its filename.
If I execute the following:
user@machine$ findme pdf classifi
It will search for all pdf
files with classifi
in its filename. So I may get something like the following result.
1:/home/user/Dropbox/SharedWithFriends/math/classifications2000.pdf
2:/home/user/Dropbox/SharedWithFriends/math/classifications2010.pdf
The question is: "Can you give me a bash script code in which after showing the results ask me for a number and a viewer, to automate my next job?"
for example I would like, if I enter:
> 2 evince
the script executes evince
on the 2
nd item of the search result, i.e.,
if this is what I entered on the previous search result it executes:
evince /home/user/Dropbox/SharedWithFriends/math/classifications2010.pdf
findme
to have a prompt at the end for you to enter the item # and viewer, or would you leavefindme
unchanged and instead have a separate, second functionopenme
that accepted2 evince
as parameters? – Jeff Schaller Nov 02 '16 at 19:31