Skip to content

Fix problems caused by echo when the messages resembles some options or when "shopt -s xpg_echo" is set - #47

Merged
urbainvaes merged 2 commits into
urbainvaes:masterfrom
akinomyoga:work-around-xpg_echo
Jan 8, 2021
Merged

urbainvaes merged 2 commits into
urbainvaes:masterfrom
akinomyoga:work-around-xpg_echo

Conversation

@akinomyoga

Copy link
Copy Markdown
Collaborator

In general, we need to carefully use the builtin echo when the message can contain arbitrary strings.

  • The echo builtin accepts options such as -n, -e, or -- (actually the set of supported options differs between shells), which means that when the message text is confusing with these options, echo behaves in a unexpected way.
  • When a user sets shopt -s xpg_echo in .bashrc or set -o BSD_ECHO in .zshrc, the builtin echo processes backslashes in the message as an escape sequence, which would also cause unexpected behavior when the mark name, FZF_MARKS_FILE, or the directory paths contain backslashes.

So, when the message can contain arbitrary strings, we can use the printf '%s\n' ... idiom instead. Here is the fix.

@urbainvaes

Copy link
Copy Markdown
Owner

Many thanks, I wasn' aware that echo could cause issues. And the herestrings are much better than the previous solution! :)

@urbainvaes
urbainvaes merged commit 15ceb2a into urbainvaes:master Jan 8, 2021
@akinomyoga
akinomyoga deleted the work-around-xpg_echo branch January 8, 2021 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants