Keep getting errors for my code in Putty

LostStudent2020

New Member
Joined
Nov 23, 2020
Messages
2
Reaction score
0
Credits
37
I have a homework assigment. I am trying to get this menu to work, but when I go to run it I keep getting errors.

Basically:
Line 3: $'\r': command not found
Line 6: $'\r': command not found
Line 8: $'\r': command not found
Line 10: $'\r': command not found
Line 31: syntax error near unexpected token '$'in\r'
Line 31: 'case $userIn" in

I don't know if I;ve just been staring at it too long or what. But I cannot figure out the issue.

Here is my code:

#!/bin/bash

until [ "$userIn" = "j" ] #loop that will keep the menu going until user
#selects j to quit it
or main menu
do
echo -e "\n Command Menu\n "
echo
echo "a. Emailer Program"
echo "b. Users Currently Logged On"
echo "c. Current Date and Time"
echo "d. This Months Calendar"
echo "e. Current Working Directory"
echo "f. Contents of Working Directory"
echo "g. Find the IP of a Web Address"
echo "h. See your Fortune"
echo "i. Print a File (on the screen"
echo "j. Exit Menu"
echo

#User will need to select which function they want to go with
echo -n 1 -p "Please select a letter from the menu: "
case "$userIn" in

#function used to collect the users subject, email address they want to send to
#and the file they want to attach
a|A) echo
echo -n "Please enter the subject of your message: "
read userMessage
echo
echo -n "Please enter the email address you're sending to: "
read userAddress
echo
echo -n "Please enter the filename for the attachment: "
read emailFile
mail -s "$userMessage" "$userAddress" < "$emailFile"
echo
;;

#This function uses the who command to find who is currently logged on
b|B) echo
who
echo
;;

#Using the date command to pull up current date and time
c|C) echo
date
echo
;;

#Using the cal command to show current months calendar
d|D) echo
cal
echo
;;

#using pwd command to pull up current working directory
e|E) echo
pwd
echo
;;

#command of ls to show what the contents of the working directory are
f|F) echo
ls
echo
;;

#commands to look up the IP address of a webaddress
g|G) echo
echo -n "Please enter the web address to look up: "
read userAddress
echo
host "$userAddress"
echo
;;

#Command to produce a fortune for the user
h|H) echo
fortune
echo
;;

#command to pull up the contents of a file on screen
i|I) echo
echo -n "Please enter a filename to see its contents: "
read userFile
echo
;;

#command to exit the menu when the user is finished with it
j|J) echo
echo "Thank you for using this menu. Goodbye."
echo
;;
#final command a user can choose from to execute

#if the user has not selected j then the program will loop back to the main menu

esac
 


From the errors - I’d say that you have some Windows/DOS style \r\n line endings in your script.
Use dos2unix to strip out the \r characters:
Bash:
dos2unix /path/to/yourscript

Then try to run your script again!
 

Members online


Top