-
Notifications
You must be signed in to change notification settings - Fork 3
Fix bash syntax error in process substitution #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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.
|
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! |
|
|
||
| output_paths=() | ||
|
|
||
| # EXPLANATION: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace all these lines with the following to fix the merge conflict:
| # 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}" |
|
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)
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.