linux – What is the purpose of the -e flag in this script?

linux – What is the purpose of the -e flag in this script?

The -e flag enables interpretation of the following backslash-escaped
characters in each STRING:

a          alert (bell)

b          backspace

c          suppress trailing newline

e          escape 

f          form feed

n          new line

r          carriage return

t          horizontal tab

v          vertical tab

\          backslash

NNN
      the character whose ASCII code is NNN (octal); if NNN is not
      a valid octal number, it is printed literally.

xnnn
      the character whose ASCII code is the hexadecimal value 
      nnn (one to three digits)

Source: http://ss64.com/bash/echo.html

-e enables interpretation of backslash escapes, but answering your question, about the purpose of it being there, it seems to be none at all. It can even be harmful. echo -e is useful if you want to include those backslashed characters in the string, but that is not the case in your example, unless $file has them, and then this can happen:

$ touch test\test
$ ls
exist.sh  testtest
$ ./exist.sh test\test
File test   est exists

Without the -e you get the correct file name. Of course, this is all academic because its unlikely that files will contain backslashed entities, but then we can conclude those switches were put there with the express goal of confusing you.

linux – What is the purpose of the -e flag in this script?

Leave a Reply

Your email address will not be published. Required fields are marked *