So I'm trying to write a shell script to take an input as below:
bash whichday Jan 10 2017
and it should take that input and print out what day it occurs on. Below is the script I'm trying to use:
#!/bin/bash
if [ $# -ne 3 ]
then
echo "Please enter the month day year (example: Jan 5 2002)"
else
str=\"$1" "$2" "$3\"
echo $str
date -d $str +%A
fi
but everytime I run this, I get the following output:
"Jan 10 2017"
date: extra operand ‘2017"’
Try 'date --help' for more information.
When I do
date -d "Jan 10 2017" +"%A"
on command line, it outputs the correct day (Tuesday), but the script, which should be executing the exact same command, doesn't work. Please help, I don't understand why this is happening.