Wednesday, May 8, 2024
 Popular · Latest · Hot · Upcoming
19
rated 0 times [  19] [ 0]  / answers: 1 / hits: 3323  / 3 Years ago, wed, may 12, 2021, 3:21:00

I'm trying to pipe the result of a find command to a bash script. This is to simplify (maybe automate) a process I have been working on.


This is the command I would like to run


find . -type f -iname '*.mp4' -exec echo {}|./indexer.sh ;


indexer.sh is ofc chmod +x so it can execute.


indexer.sh currently contains


#!/bin/zsh
read foo
echo "You entered '$foo'"

And if I run $ echo foo | ./indexer.sh I get the output of
You entered 'foo'


But when I run find . -type f -iname '*.mp4' -exec echo {}|./indexer.sh ; I receive the following error message:


find: -exec: no terminating ";" or "+"
You entered ''

So how can I pipe the output of find, into my script?


More From » bash

 Answers
1

I would rewrite it using a parameter instead of a read statement and piping,


find . -type f -iname '*.mp4' -exec ./indexer.sh {} ;

with the following indexer.sh,


#!/bin/zsh

echo "You entered '$1'"

[#432] Thursday, May 13, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ionodest

Total Points: 252
Total Questions: 122
Total Answers: 100

Location: Liechtenstein
Member since Tue, Apr 27, 2021
3 Years ago
ionodest questions
Sat, Jan 1, 22, 06:31, 2 Years ago
Tue, Feb 22, 22, 09:46, 2 Years ago
Thu, Jun 30, 22, 12:12, 2 Years ago
Wed, May 4, 22, 18:48, 2 Years ago
;