3
echo <Search> | find / -name <Search> 

I am trying to achieve something like this. To get the same result, I am storing my search on a variable and then using find on it but obviously I am not satisfied with it. It would be awesome if I could pipe that right into find.

6
  • why do you prefer the pipe over SEARCH='*.txt' find / -name $SEARCH Commented May 2, 2020 at 14:16
  • It would be convenient to keep the pipe going. :D Commented May 2, 2020 at 14:21
  • Show us what you have. Don't describe it. Commented May 2, 2020 at 14:25
  • It would be an overkill to show my whole script thus I narrowed it down to the problem itself. Besides, the question is pretty simple by any standard. Commented May 2, 2020 at 14:26
  • You should provide a bit more of the left side of the pipe. You simplified it so much, it is not really useful. Commented May 2, 2020 at 14:34

2 Answers 2

4

You could use xargs ex.

echo "*.c" | xargs -I% find / -name "%" 
1
  • There you go! Thanks man! The irony is I was already using xargs on my script! lol. It was right under my nose. BTW, the super user vibe was duly noted from "*.c". XD Commented May 2, 2020 at 14:35
0

You can substitute like this:

$ SEARCH='*mp4' $ find / -name "$(echo $SEARCH)" 

This will pipe the output of the command into a variable and do things like this:

$ find / -name "$(grep XYZ | cut -f2)" 

You can see more about Command Substitution.

4
  • From what I understood, this is what OP is doing now but they are not satisfied with it. Commented May 2, 2020 at 14:18
  • BTW, you don't need echo. Commented May 2, 2020 at 14:19
  • I understood the OP is doing SEARCH='*.txt' find / -name $SEARCH. The echo is there only to let him know it is a 'pipe-ish' solution that he can substitute with other commands. Commented May 2, 2020 at 14:19
  • Both of these will work. I like the 2nd better. However both will stall the pipe. find can not start until cut ends. It is good if the grep ... cut is quick, and produces little output. Commented May 2, 2020 at 14:29

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.