[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Use `find' "-printf" predicate inside bash script
From: |
JB |
Subject: |
Re: Use `find' "-printf" predicate inside bash script |
Date: |
Tue, 19 Oct 2021 19:40:46 +0000 |
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> Date: Mon, 18 Oct 2021 16:39:27 -0400
> From: Greg Wooledge greg@wooledge.org
> To: help-bash@gnu.org
> Subject: Re: Use `find' "-printf" predicate inside bash script
>
> On Mon, Oct 18, 2021 at 08:24:58PM +0000, JB wrote:
>
> > #!/bin/bash
> > args_find='-type f -mtime -1 -delete -printf "deleted file: %f\\n"'
> > find /tmp/ $args_find
> >
>
> https://mywiki.wooledge.org/BashFAQ/050
>
> tl;dr: put the args in an array, not a string variable. Use an array
> expansion, not an unquoted string variable expansion.
Had tried that already but it failed because $args_find[@] wasn't quoted.
Didn't test quoting because $args_find[*] broke `find', so I figured
double-quoting $args_find[@] would as well. This works:
find /tmp/ "$args_find[@]"
Thanks.
Sent with ProtonMail Secure Email.