help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Use `find' "-printf" predicate inside bash script


From: Alex fxmbsw7 Ratchev
Subject: Re: Use `find' "-printf" predicate inside bash script
Date: Mon, 18 Oct 2021 22:35:06 +0200

fyi, it works only if written separatly cause one would need eval to make
bash parse the quotes u uses inside

the better approach is array elements, one per arg

find=( find -opt1 -opt2 sub2 )
"${find[@]}"

On Mon, Oct 18, 2021, 22:31 JB <freebsdlists.admin@protonmail.com> wrote:

> This `find' command works on the command line:
>
>         find /tmp/ -type f -mtime -1 -delete -printf "deleted file: %f\n"
>
> But it doesn't work inside this script:
>
>         #!/bin/bash
>         args_find='-type f -mtime -1 -delete -printf "deleted file: %f\n"'
>         find /tmp/ $args_find
>
> It only works when written like this:
>
>         #!/bin/bash
>         args_find="-type f -mtime -1 -delete -printf"
>         args_print="deleted file: %f\n"
>         find /tmp/ $args_find "$args_print"
>
> I've tried using arrays with both "@" and "*", but same result.
> I tried escaping the double-quotes, but `find' complains:
>         warning: unrecognized escape `\"'
>         paths must precede expression: `file'
>
> What's the proper way to do this inside a variable which doesn't trip up
> "-printf"?
>
> Sent with ProtonMail Secure Email.
>
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]