Skip to content
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

echo recognizes its options at the start of a quoted argument #7614

Closed
programandala-net opened this issue Jan 9, 2021 · 1 comment
Closed
Labels
bug Something that's not working as intended
Milestone

Comments

@programandala-net
Copy link

I'm running fish 3.1.2 in Debian 10.7, on x86_64. I compiled the sources. I use no third-party customization. I've been using fish for more than a year, and it's my default shell.

I have found out this while writting a tool in fish:

echo "-n comp";echo "lete"
echo '-n comp';echo 'lete'
echo "-s comp" "lete"
echo '-s comp' 'lete'
echo "-e comp\x6Cete"
echo '-e comp\x6Cete'

Output:

-n complete
-n complete
-s complete
-s complete
-e complete
-e complete

Output of the same code in Bash:

-n comp
lete
-n comp
lete
-s comp lete
-s comp lete
-e comp\x6Cete
-e comp\x6Cete

In fish, echo recognizes its own options when they are at the start of the first quoted argument. When a space is at the start of the quoted string, the option is not recognized anymore. For example echo " -e comp\x6Cete" displays the literal string as expected.

Maybe I'm missing something, but it seems a bug. I've searched the manual page, the website documentation and the GitHub issues, but found nothing about this.

Thank you.

@faho faho added the bug Something that's not working as intended label Jan 9, 2021
@faho faho added this to the fish-future milestone Jan 9, 2021
@faho
Copy link
Member

faho commented Jan 9, 2021

Ahahaha, what's happening here is that echo ignores unknown options by putting them back into the arguments.

So it interprets "-e foo" as basicaly -e -" " -f -o -o for the purposes of parsing options, gets to the -" " (yes, a "dash-space"), decides that "space" isn't a valid option and puts the entire token back.

So it acts on the -e and prints it.


The workaround is simple: Use --. Fish's echo supports it, in flagrant (and proud) violation of POSIX. echo -- "-n foo" prints -n foo with a newline.

@faho faho closed this as completed in 1dd776e Jan 9, 2021
@zanchey zanchey modified the milestones: fish-future, fish 3.2.0 Jan 12, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something that's not working as intended
Projects
None yet
Development

No branches or pull requests

3 participants