Amey Joshi
Amey Joshi

Reputation: 1

what is the purpose of -e in shell scripting in this code?

echo "Enter file name "
            read filename
            while [ -e $filename ] ;
            do
                echo -e "\n\tFile is already exits !!"
                echo -e "Do u want to overwrite ? (y/n) :"
                read ch
                if [ $ch == "y" ];then
                    break  
                else    
                    echo -e "\n\tRe-enter file name :"
                    read filename
                fi
            done

Upvotes: 0

Views: 159

Answers (1)

ljden
ljden

Reputation: 392

There are 2 different occurrences of -e in the script.

In the case of [ -e $filename ], the [ is an alias for the command test so by referring to the documentation manual (try man test) we can see that the -e tests to see if the file specified exists:

-e FILE FILE exists

From the echo entry in the documentation manual (try man echo on your favourite terminal):

-e enable interpretation of backslash escapes

This means, instead of displaying a backslash as a character, backslash characters should be interpreted as an escape character.

Try running echo "this is\n a test" and echo -e "this is\n a test" to see the difference

Upvotes: 1

Related Questions