4 ms·
Yes. The famous echo on Linux systems does not have it and therefore it's impossible to print the string "-n o p e", because -n will be interpreted as an option
by ribcage 2y ago
Yes. The famous echo on Linux systems does not have it and therefore it's impossible to print the string "-n o p e", because -n will be interpreted as an option.
- bonzini 2y agoecho is not portable anyway, use "printf %s STRING" or "printf '%s\n' STRING".
- ribcage 2y agoYes, that's what I use. Sometimes I still get tempted to use echo because there's less typing...
- ezequiel-garzon 2y agoIt does if single or double quotes are used, right? Which would be necessary (or preferred to multiple backslashes) quite often.
- bonoboTP 2y agoNo, the quotes are not seen by the program. The program receives a list of strings, it does not get the information about whether and how those strings were originally quoted in the shell. Programs can also be directly called with lists of strings as in execve, so often it does not even make sense to ask if the arguments were quoted or not. Quotes live on a different level of abstraction.
- danadam 2y ago> No, the quotes are not seen by the program. The program receives a list of strings, it does not get the information about whether and how those strings were originally quoted in the shell. With quotes the program will receive a single argument -n␣o␣p␣e instead of multiple ones -n, o, p, e. At least it works on the machine here: ]$ echo "-n o p e" -n o p e ]$ /bin/echo "-n o p e" -n o p e
- bonoboTP 2y agoYes, I think there was some misremembering here. The nontrivial thing is to print out -n itself with echo. For example, echo doesn't treat "--" specially, so "echo -- -n" prints "-- -n".
- account42 2y agoNote that this is true for POSIX sytems but not e.g. for Windows. There the program receives the command-line as-is and is responsible for parsing it into an array. There are two different standard functions to do this parsing for you (with slightly different quoting behavior) but you could also create your own that requires options to not be quoted.