diff mbox series

[kvm-unit-tests,RFC,04/17] shellcheck: Fix SC2094

Message ID 20240405090052.375599-5-npiggin@gmail.com (mailing list archive)
State New, archived
Headers show
Series add shellcheck support | expand

Commit Message

Nicholas Piggin April 5, 2024, 9 a.m. UTC
SC2094 (info): Make sure not to read and write the same file in the same
  pipeline.

This is not as clearly bad as overwriting an input file with >, but
could appended characters possibly be read in from the input
redirection?

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 scripts/arch-run.bash | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Andrew Jones April 5, 2024, 2:17 p.m. UTC | #1
On Fri, Apr 05, 2024 at 07:00:36PM +1000, Nicholas Piggin wrote:
>   SC2094 (info): Make sure not to read and write the same file in the same
>   pipeline.
> 
> This is not as clearly bad as overwriting an input file with >, but
> could appended characters possibly be read in from the input
> redirection?
> 
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
>  scripts/arch-run.bash | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
> index 1901a929f..472c31b08 100644
> --- a/scripts/arch-run.bash
> +++ b/scripts/arch-run.bash
> @@ -492,6 +492,8 @@ env_file ()
>  
>  env_errata ()
>  {
> +	local new_env
> +
>  	if [ "$ACCEL" = "tcg" ]; then
>  		export "ERRATA_FORCE=y"
>  	elif [ "$ERRATATXT" ] && [ ! -f "$ERRATATXT" ]; then
> @@ -500,7 +502,8 @@ env_errata ()
>  	elif [ "$ERRATATXT" ]; then
>  		env_generate_errata
>  	fi
> -	sort <(env | grep '^ERRATA_') <(grep '^ERRATA_' $KVM_UNIT_TESTS_ENV) | uniq -u >>$KVM_UNIT_TESTS_ENV
> +	new_env=$(sort <(env | grep '^ERRATA_') <(grep '^ERRATA_' $KVM_UNIT_TESTS_ENV) | uniq -u)
> +	echo "$new_env" >>$KVM_UNIT_TESTS_ENV
>  }
>  
>  env_generate_errata ()
> -- 
> 2.43.0
>

Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
diff mbox series

Patch

diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
index 1901a929f..472c31b08 100644
--- a/scripts/arch-run.bash
+++ b/scripts/arch-run.bash
@@ -492,6 +492,8 @@  env_file ()
 
 env_errata ()
 {
+	local new_env
+
 	if [ "$ACCEL" = "tcg" ]; then
 		export "ERRATA_FORCE=y"
 	elif [ "$ERRATATXT" ] && [ ! -f "$ERRATATXT" ]; then
@@ -500,7 +502,8 @@  env_errata ()
 	elif [ "$ERRATATXT" ]; then
 		env_generate_errata
 	fi
-	sort <(env | grep '^ERRATA_') <(grep '^ERRATA_' $KVM_UNIT_TESTS_ENV) | uniq -u >>$KVM_UNIT_TESTS_ENV
+	new_env=$(sort <(env | grep '^ERRATA_') <(grep '^ERRATA_' $KVM_UNIT_TESTS_ENV) | uniq -u)
+	echo "$new_env" >>$KVM_UNIT_TESTS_ENV
 }
 
 env_generate_errata ()