From 94e73e5fa4752085a75b457bc29afcc2754c07db Mon Sep 17 00:00:00 2001 From: Gabe Torres <69164745+gabtorre@users.noreply.github.com> Date: Fri, 20 Dec 2024 11:33:11 -0800 Subject: [PATCH] Update batch spec search result looping example (#870) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The original snippet has some issues: The loop will not handle spaces correctly and may misinterpret the path. The entire string is treated as one entity due to the quotes, leading to incorrect processing. Updated the loop handling in the script to correctly process file paths by switching from space-delimited to newline-delimited entries. This ensures the handling of paths with spaces or special characters. Added IFS=$'\n' for proper splitting and quoting of paths in the loop for safety. ![Screenshot 2024-12-19 at 3 10 35 PM](https://github.com/user-attachments/assets/4f10c4bb-cba2-4659-862f-4980c2c0b7c1) Spaces in file names ![Screenshot 2024-12-19 at 3 09 23 PM](https://github.com/user-attachments/assets/771935b7-6d84-4bf7-bc0e-f7fe1b01959c) ## Pull Request approval You will need to get your PR approved by at least one member of the Sourcegraph team. For reviews of docs formatting, styles, and component usage, please tag the docs team via the #docs Slack channel. --- docs/batch-changes/batch-spec-cheat-sheet.mdx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/batch-changes/batch-spec-cheat-sheet.mdx b/docs/batch-changes/batch-spec-cheat-sheet.mdx index 1e1b89ca5..2f7e510ba 100644 --- a/docs/batch-changes/batch-spec-cheat-sheet.mdx +++ b/docs/batch-changes/batch-spec-cheat-sheet.mdx @@ -14,9 +14,11 @@ on: steps: - run: | - for file in "${{ join repository.search_result_paths " " }}"; + IFS=$'\n' + files="${{ join repository.search_result_paths "\n" }}" + for file in $files; do - sed -i 's/OLD-VALUE/NEW-VALUE/g;' ${file} + sed -i 's/OLD-VALUE/NEW-VALUE/g;' "${file}" done container: alpine:3 ```