From 3282ef2a353b7202e211ba027b930360ca5b24e7 Mon Sep 17 00:00:00 2001 From: Clement Date: Fri, 6 Dec 2024 01:32:07 +0800 Subject: [PATCH] Use read -a for safety --- 2024/day-5/solution-2.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/2024/day-5/solution-2.sh b/2024/day-5/solution-2.sh index 2cbc576..7505ce1 100644 --- a/2024/day-5/solution-2.sh +++ b/2024/day-5/solution-2.sh @@ -27,7 +27,10 @@ INPUT_RULES=$(cat input-rules) do # Loop through rules and build all the KVs DAG_GREP_EXPR=$( printf "%s" "$CACHED_LINE" | paste -s -d '|' ) - KV_ARRAY=( $( < input-rules grep -E "($DAG_GREP_EXPR)\\|($DAG_GREP_EXPR)" | tr '|' ' ' | paste -s -d ' ') ) + read -r -a KV_ARRAY <<< "$( + < input-rules grep -E "($DAG_GREP_EXPR)\\|($DAG_GREP_EXPR)" | + tr '|' ' ' | + paste -s -d ' ')" # Going through dependencies to find final key KEY=${KV_ARRAY[0]} while true