1

I'm creating a shell script to perform basic math operations using WSL. Im using ubuntu terminal for this purpose.

#!/bin/bash
echo "+ : Addition (a+b)"
echo "- : Subtraction (a-b)"
echo "* : Multiplication (a*b)"
echo "/ : Division (a/b)"
read -p "Choose operation: " op
read -p "Enter value of a: " a
read -p "Enter value of b: " b
case $op in
"+")
echo $a "+" $b "=" $((a+b))
;;
"-")
echo $a "-" $b "=" $((a-b))
;;
"*")
echo $a "*" $b "=" $((a*b))
;;
"/")
echo $a "/" $b "=" $((a/b))
;;
esac

this is the code. Im executing this code using command

sh add.sh

"add.sh" is the file name

and I'm getting this error message

1 Answers1

0

you have dos line endings. You can use fromdos to get rid of them

fromdos test.txt

The above example would take a MS-DOS or Microsoft Windows file or other file with different line separators and format the file with new line separators to be read in Linux and Unix.

Ref: https://stackoverflow.com/a/12509995/1118978

Derviş Kayımbaşıoğlu
  • 28,492
  • 4
  • 50
  • 72