0

I have read other articles but I can't manage to found the solution to this problem. I am running the shell script on a Ubuntu terminal.

del2.sh:

echo "Subject Deletion"
echo "Enter 0 to return to Main Menu"
echo -n "Enter subject name to delete it"
read name1

if [ "$name1" == "0" ] then
echo - n "No changes made"
exit 0

else rm $name.txt

fi

Terminal:

enter image description here

Ashish Rao
  • 81
  • 3
  • 11
  • 1
    Your file is saved with DOS newlines. – Charles Duffy Apr 08 '20 at 21:26
  • Please do not post pictures of text. Just post the text. – KamilCuk Apr 08 '20 at 21:27
  • BTW, don't put a space between the `-` and the `n` in `-n`; quote your expansions (`rm "$name.txt"`), and in general, it's safer to use `printf '%s' "some string"` than `echo -n "some string"`; on the last point, see the APPLICATION USAGE section of the POSIX `echo` spec at https://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html, and the excellent answer by Stephane at https://unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo – Charles Duffy Apr 08 '20 at 21:28
  • Also, one should always use `IFS= read -r name1` unless you have an explicit reason to *not* do those things; by default, `read` munges input with backslashes, and trims leading and trailing whitespace. – Charles Duffy Apr 08 '20 at 21:29
  • @CharlesDuffy I am new at this so I don't really know much. What does it mean that my file is saved with DOS newlines? – Ashish Rao Apr 08 '20 at 21:37
  • DOS/Windows text files separate lines with two characters, a CR and a LF (because this is a separator, not a delimiter, there isn't such a sequence after the very last line). UNIX text files end *all* lines, including the last one, with an LF. – Charles Duffy Apr 08 '20 at 21:41
  • When a CR is printed, it sends the cursor back to the beginning of the current line. That's why your error messages contain lines that are partially overwritten. – Charles Duffy Apr 08 '20 at 21:42
  • @CharlesDuffy I got it thank you so much! – Ashish Rao Apr 08 '20 at 21:44

0 Answers0