3

息子のために書いているスクリプトに問題があります。私の意図は、彼が自分の雑用を覚えていることを単純に思い出させることです. 最近 PowerShell を使い始めたばかりで、とても楽しんでいます。私は数冊の本を購入し、他の多くの記事を読んできました。

私がこれまでに得たものは以下のとおり-or です.

    ## REMINDERS TO DO CHORES ##

$sun = "Sunday"
$mon = "Monday"
$tue = "Tuesday"
$wed = "Wednesday"
$thu = "Thursday"
$fri = "Friday"
$sat = "Saturday"

$today = (get-date).DayOfWeek

$choreVac = "Vacuum the rooms and stairs"
$choreBath = "Clean the Bathroom Including emptying the garbage"
$choreOther = "No Chores Today -- But keep dishes done up"


if($today -eq $mon -or $wed -or $fri) {
msg /time:2500 * "Today is a Chore Day:  your job is to $choreVac" 
}

elseif ($today -eq $tue -or $sat ) {
msg /time:2500 * "Today is a Chore Day: your job is to $choreBath and PLEASE do a good job"
}
else {
msg /time:2500 * $choreOther
}

問題は、その日に正しく評価されているとは思えないので、今日が火曜日の場合、評価結果は$mon -or $wed -or $fri

これを次のように毎日再コーディングすると、期待どおりに機能します。で動作しないのはなぜ-orですか?

if($today -eq $tue) {
msg /time:2500 * $choreBath
}
4

3 に答える 3

1

これが修正された完全なコードで、私が望んでいたとおりに機能しています。

    ## REMINDERS TO DO CHORES ##

$sun = "Sunday"
$mon = "Monday"
$tue = "Tuesday"
$wed = "Wednesday"
$thu = "Thursday"
$fri = "Friday"
$sat = "Saturday"

$today = (get-date).DayOfWeek

$choreVac = "Vacuum The Apt"
$choreBath = "Clean the Bathroom Including empting the garbage"
$choreOther = "NO CHORES TODAY -- BUT YOU CAN Keep dishes done up, and Keep Garbage from Overflowing AND CLEAN YOUR ROOM and OR Do Laundry!!!. Especially your bedding"

if($today -in ($mon, $wed ,$fri) ) {
msg /time:2500 * "Today is a Chore Day:  your job is to $choreVac" 
}

elseif ($today -in ($tue,$sat)) {
msg /time:2500 * "Today is a Chore Day: your job is to $choreBath and PLEASE do a good job"
}
else {
msg /time:2500 * $choreOther
}
于 2015-08-19T00:37:14.020 に答える