Skip to content

Instantly share code, notes, and snippets.

@andy722
Created May 20, 2024 08:41
Show Gist options
  • Save andy722/8a50eb89edfa9edbddb1b81318f4e13c to your computer and use it in GitHub Desktop.
Save andy722/8a50eb89edfa9edbddb1b81318f4e13c to your computer and use it in GitHub Desktop.
#
# Remove `line` from `array`.
# If `line` occurs multiple times, only a single occurrence is removed.
#
new_array=()
skipped=0
for value in "${array[@]}"; do
if [ "$value" == "$line" ] && [ $skipped -eq 0 ]; then
skipped=1
else
new_array+=("$value")
fi
done
array=("${new_array[@]}")
unset new_array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment