c0defellas / enzo

core utilities
11 stars 2 forks source link

Add echo utility #5

Closed i4ki closed 7 years ago

i4ki commented 7 years ago

It's so small that I don't see much benefit of splitting in a separate function. A next improvement could be testing, and then we'll need to put on a proper function...

Depends on #1 (because I'm stupid)

@lborguetti @patito @katcipis @rzanato

Closes #2

patito commented 7 years ago

I have tested here and is working and I've also compared the behaviour with my OS /bin/echo. I think we should put the code in a function to test purpose. What do u think?

i4ki commented 7 years ago

It's a good idea for testing but I don't know for feature comparison.

The GNU echo have -e flag for backslash interpretation, but this is required for POSIX shells that do not interpret the string arguments.

Using bash:

[i4k@johncarter cat]$ echo "test\n"
test\n
[i4k@johncarter cat]$ echo "hello\tworld"
hello\tworld

Using nash:

echo "test\n"
test

λ> echo "hello\tworld"
hello   world
# Escape for non-interpretation
λ> echo "hello\\tworld"
hello\tworld

Nash does it by default, because this is what we want in most cases.

I'll put the echo in a separate func.

i4ki commented 7 years ago

There's room for improvements on nash about this too:

λ> echo "\x41"
ERROR: line 1:1:8: Escape types 'x', 'u' and 'U' aren't implemented yet