Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Why am I getting 'command not found' errors for -e, -w, -r and -x in this program?

+2 votes
asked May 22, 2021 by Sabiha M (140 points)
#!/bin/bash
echo "enter file name"
 read fn
if test
-e $fn
then
echo "file exists"
else
echo "file does not exists"
fi
if test
-w $fn ; then
echo "writable"
fi
if test
-r $fn
then
echo "readable"
fi
if test
-x $fn
then
echo "executable"
fi
if test -d $fn
then
echo "directory"
fi

3 Answers

0 votes
answered Dec 19, 2021 by WHITELIGHT UNSEEN (370 points)
what is the program languge
commented Dec 19, 2021 by KUSH RAJ (100 points)
what is the proframming language and use semicolone lol
commented Dec 19, 2021 by Peter Minarik (86,040 points)
Bash, by the look of it.
0 votes
answered Dec 19, 2021 by Peter Minarik (86,040 points)

It is possible that the owners or the site have disabled the usage of the read command, l hence your script does not work.

0 votes
answered Jan 2, 2022 by xDELLx (10,500 points)

#!/bin/bash
echo "enter file name"
 read fn
if test -e $fn
then
echo "file exists"
else
echo "file does not exists"
fi
if test -w $fn ; then
echo "writable"
fi
if test -r $fn
then
echo "readable"
fi
if test -x $fn
then
echo "executable"
fi
if test -d $fn
then
echo "directory"
fi


Looks like syntax was wrong, or multiline identifier "\" was not added at end of line in if conditions.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...