[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: printf '%s\n' "$@" versus <<< redirection
From: |
Greg Wooledge |
Subject: |
Re: printf '%s\n' "$@" versus <<< redirection |
Date: |
Mon, 20 Feb 2023 07:42:19 -0500 |
On Mon, Feb 20, 2023 at 12:31:11PM +0000, goncholden wrote:
> Does the problem of disappearing variables exist in
> calls to awk ?
>
> for arg in "$@"; do
> printf '%s\n' "$arg" | awk '...'
> done
Both printf and awk will be executed in subshells. However, awk is
already an external program, so it's *always* executed as a separate
process. awk has its own variables which are never shared back to
the script from which you call it.
> or should one use
>
> for arg in "$@"; do
> awk '...' < <(printf '%s\n' "$arg")
> done
That wouldn't change anything. awk is still an external program, and
is therefore still executed as a separate process, with its own private
variables and so on.
> There is also the possibility of putting the awk command in the process
> substitution, not the printf command:
>
> for arg in "$@"; do
> while read ...; do
> ...
> done < <(awk '...' <<< "$arg")
> done
Without knowing what your awk command *does* it's hard to give advice,
but it might be more efficient if you call it once instead of once
per argument.
theone() {
printf '%s\n' "$@" | awk 'whatever'
}
This is contingent upon your awk command being able to handle the full
input stream sent in this way.
- Re: printf '%s\n' "$@" versus <<< redirection, (continued)
- Re: printf '%s\n' "$@" versus <<< redirection, Mike Jonkmans, 2023/02/18
- Re: printf '%s\n' "$@" versus <<< redirection, Kerin Millar, 2023/02/18
- Re: printf '%s\n' "$@" versus <<< redirection, goncholden, 2023/02/19
- Re: printf '%s\n' "$@" versus <<< redirection, Kerin Millar, 2023/02/19
- Re: printf '%s\n' "$@" versus <<< redirection, Greg Wooledge, 2023/02/19
- Re: printf '%s\n' "$@" versus <<< redirection, Kerin Millar, 2023/02/19
- Re: printf '%s\n' "$@" versus <<< redirection, Greg Wooledge, 2023/02/19
- Re: printf '%s\n' "$@" versus <<< redirection, Kerin Millar, 2023/02/19
- Re: printf '%s\n' "$@" versus <<< redirection, Greg Wooledge, 2023/02/19
- Re: printf '%s\n' "$@" versus <<< redirection, goncholden, 2023/02/20
- Re: printf '%s\n' "$@" versus <<< redirection,
Greg Wooledge <=
- Re: printf '%s\n' "$@" versus <<< redirection, goncholden, 2023/02/20
- Re: printf '%s\n' "$@" versus <<< redirection, Chet Ramey, 2023/02/20
- Re: printf '%s\n' "$@" versus <<< redirection, Mike Jonkmans, 2023/02/20
- Re: printf '%s\n' "$@" versus <<< redirection, Greg Wooledge, 2023/02/20
- Re: printf '%s\n' "$@" versus <<< redirection, Mike Jonkmans, 2023/02/21
- Re: printf '%s\n' "$@" versus <<< redirection, Chet Ramey, 2023/02/21
- Re: printf '%s\n' "$@" versus <<< redirection, Chet Ramey, 2023/02/21