Fix bash syntax error in process substitution#20
Open
segudev wants to merge 5 commits intomieubrisse:mainfrom
Open
Fix bash syntax error in process substitution#20segudev wants to merge 5 commits intomieubrisse:mainfrom
segudev wants to merge 5 commits intomieubrisse:mainfrom
Conversation
Refactored the fzf command execution to use command substitution instead of process substitution with conditional logic. The original code had a `return` statement inside a process substitution which created a bash syntax error. Changes: - Capture fzf output in a variable first - Check exit status separately - Use here-string to process the output - Replace `return` with `exit 1` for proper subprocess handling This improves compatibility across different bash versions and makes the code more readable. Fixes the "bad substitution: no closing ')'" error.
Owner
|
Thank you @segudev! I just pushed a cleanup to main that's going to cause a conflict with your branch; I'll put the fix you need in a comment. Excited to get this merged! |
mieubrisse
reviewed
Jul 31, 2025
|
|
||
| output_paths=() | ||
|
|
||
| # EXPLANATION: |
Owner
There was a problem hiding this comment.
Replace all these lines with the following to fix the merge conflict:
Suggested change
| # EXPLANATION: | |
| # EXPLANATION: | |
| # -m allows multiple selections | |
| # --ansi tells fzf to parse the ANSI color codes that we're generating with fd | |
| # --scheme=path optimizes for path-based input | |
| # --with-nth allows us to use the custom sorting mechanism | |
| fzf_output="$(FZF_DEFAULT_COMMAND="bash ${script_dirpath}/list-files.sh ${*}" fzf \ | |
| -m \ | |
| --ansi \ | |
| --bind='change:top' \ | |
| --scheme=path \ | |
| --preview="bash ${script_dirpath}/preview.sh {}")" | |
| if [ "${?}" -ne 0 ]; then | |
| exit 1 | |
| fi | |
| while IFS="" read -r line; do # IFS="" -> no splitting (we may have paths with spaces) | |
| output_paths+=("${line}") | |
| done <<< "${fzf_output}" |
Owner
|
Hey @segudev , just wanted to check if you'd still like to merge this? |
- Remove braces from $* and $@ parameter expansions to handle empty arguments - Change list-files.sh shebang from sh to bash (script uses bash arrays)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixed a bash syntax error that was causing cmdk to fail with "bad substitution: no closing ')'" error.
Root Cause
The original code used process substitution
< <(...)with conditional logic (if/return) inside it. This creates a subshell wherereturnstatements don't work properly and can cause syntax errors in different bash versions.Solution
$()to capture fzf output<<<to process the captured outputreturntoexit 1for proper subprocess handlingTesting
Changes
cmdk-core.sh: Restructured fzf execution and output processingFixes the "bad substitution" error that prevented cmdk from running.