Comment

Comment by jcranmer

I have a variable, say $X, that contains a command, and the command has quoted arguments with spaces, let's say <<echo "A B">>. Now how do I execute it? If I do $X, the result <<"A B">>, not <<A B>>. If I do "$X", it fails, because there's no filename <<echo "A B">> to execute.

In a program with proper arrays, I can instead parse X to the strings ["echo", "A B"], and then run execve to run ["echo", "A B"] without any issues. And adding another argument to make ["echo", "A B", "C"] is damn trivial.

No, bash doesn't handle arguments with spaces just fine. If you do the basic, obvious way to do things, things break, and you're expected to know magic invocations to do the right thing to handle potential spaces.

parent jcranmer 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton