Home > front end >  Case: Too many arguments error for switch in C shell
Case: Too many arguments error for switch in C shell

Time:09-17

Yes, I am using csh. No, I do not have a choice about it.

I am currently trying to calculate yesterday's date using today's date. However the switch I am using to try to set the "day" number when today is the first of the month is throwing the error Case: Too many arguments
Here is my code snippet:

#!/bin/csh


set todaysMonth = `date ' %m'`
set todaysDay = `date ' %d'`
set todaysYear = `date ' %Y'`
set yestMonth
set yestDay
set yestYear

set todaysMonth = 1
set todaysDay = 1

if ($todaysDay == 1) then
   switch ($todaysMonth)
     case 5:
     case 7:
     case 10:
     case 12: set yestDay = 30
              breaksw
     case 1:
     case 2:
     case 4:
     case 6:
     case 8:
     case 9:
     case 11: set yestDay = 31
              breaksw

     case 3:  # don't care about leap year right now
              echo "Setting yestDay to 28"
              set yestDay = 28
              breaksw
     default: echo "Failied to set yestDay"
   endsw

echo "Today:" $todaysDay
echo "Yesterday:" $yestDay
endif

Output: Case: Too many arguments

Does anyone know what's going on?

CodePudding user response:

It's not:

case <arg>: <command>

it's:

case <arg>:
   <command>

The man page does show this, but it's not telling you it will error if you don't.

You need to do this on the 4 lines.

And you need an endif.

  • Related