echo does not accept end of arguments operator

Let’s start with an example :

$ cat AI
while :
  echo "What's your name ?"
  read a
  if [ ! $a ]
  echo "Your name is :"
  echo $a
echo "Bye"

$ ./AI
What's your name ?
Your name is :

What's your name ?
Your name is :

What's your name ?
Your name is :

What's your name ?


This artificial intelligence is not very intelligent, it cannot recognize me if I am called “-e” (it is Friday, have a look at Little Bobby Tables ).

Most unix tools consider
-- signals the end of options and disables further option processing

But not echo 🙁

$ touch -e
touch: invalid option -- e
Try `touch --help' for more information.
$ touch -- -e
$ ls -l -e
ls: invalid option -- e
Try `ls --help' for more information.
$ ls -l -- -e
-rw-r--r-- 1 lsc dba 0 Oct 31 15:44 -e
$ rm -e
rm: invalid option -- e
Try `rm ./-e' to remove the file `-e'.
Try `rm --help' for more information.
$ rm -- -e
$ echo -e

$ echo -- -e
-- -e

So, what’s the solution? well, probably not using “echo”, for example printf

$ (echo “What’s your name ?”
read a
echo “Your name is :”
printf “%s\n” “$a”)
What’s your name ?
Your name is :

Leave a Reply

Your email address will not be published.