If one is (stuck) in a bathroom with a short amount of time left until sunset, and realizes that he has not yet counted Sefirah for that day, and will not be out of the bathroom before sunset, may he count in the bathroom?
Terrific question. I found a discussion of the issue by Rabbi S.B. Genut (in the case of someone locked in a bathroom) here, which I'll summarise for those for whom Hebrew is a barrier.
Firstly, we'll assume that a modern bathroom is considered a place of uncleanliness (which is a discussion in itself, since our bathrooms are pretty clean compared to those in olden times).The Mishna B'rura (Biur Halacha OC 588 s.v. שמע ט' תקיעות) quotes the Mateh Efraim (a classic work on the laws of the Days of Awe) that if someone became incontinent while blowing the shofar, he should stop. The MB asks why - after all, why should this automatically be like shema or tefillin where we explicitly are commanded to read/wear it in a clean place? It's not forbidden to do other mitzvot in an unclean place - we don't take off tzitzit when entering a bathroom.
He suggests that it might be because of מצוות צריכות כוונה, mitzvot requiring thought (as @DonielF floated in the comments). However, many hold that Rabbinical mitzvot don't require kavana, and that counting the Omer in our times is rabbinical. (Which is why if you accidentally say what day it is in answer to someone's question, you don't count with a bracha.) So he suggests that one may count without kavana (and obviously without a blessing).
However, he notes that the שו"ת מעט מים (which I think was by R' Avraham of Salonica, who was among those expelled from Spain in 1492) discusses the issue and forbids it because one cannot possibly do a mitzva without thinking about it, and that is no different from thoughts of Torah.
Another reason the MB quotes is that this might just be disrespectful of the mitzva. (Similarly, it is brought that it is forbidden to use urine to wash/sterilise a shofar [which apparently was something people did back then!] because it is disrespectful.) However, R' Genut says that if this will cause you to miss out on counting for the rest of the sefira, there is room to be lenient, just like with an onen (as @Danny Schoemann mentioned, though he sources it to the Noda B'Yehuda Mahdura Kama OC 27).
He also quotes R' Chaim Palachi (in Lev Chaim 2:123, Moed L'Kol Chai 5:6), asked about one who is imprisoned in an unclean place. He says that one may count without a bracha, just like one may give charity or slaughter an animal in an unclean place.
Finally, he notes that he asked someone to ask R' Chaim Kaniyevski shlita, who said that one may not. But there are claims that on another occasion he ruled that one may.
I would be inclined to permit it - despite Danny's (unsourced) answer forbidding it.
In סימן קצו - הלכות אונן the Kitzur Shulchan Aruch states that an Onen (a mourner before the burial takes place) should wait until after the burial to count the Omer, since an Onen is not allowed to do any Mitzvot.
However, continues the Kitzur, if waiting until after the burial would cause him to miss a day, then the Onen counts.
So we see that counting in order not to miss a day is permissible even when one may not do Mitzvoth.
I am tempted to say that your scenario is similar, though I can't prove it, yet.
סעיף י"ח: אוֹנֵן בְּלֵיל סְפִירַת הָעֹמֶר, לֹא יִסְפֹּר בַּלַיְלָה, אֶלָּא בַּיוֹם לְאַחַר הַקְּבוּרָה יִסְפֹּר בְּלֹא בְרָכָה. וּבִשְׁאָר הַלֵּילוֹת, יִסְפֹּר אַחַר כָּךְ בִּבְרָכָה. וְאִם רוֹאֶה בַּיוֹם כִּי הָאֲנִינוּת תִּמָּשֵׁךְ עַד הַלַּיְלָה, יִסְפֹּר אֲפִלּוּ בַאֲנִינוּת בְּלֹא בְרָכָה, כְּדֵי שֶׁיִסְפֹּר שְׁאָר הַלֵּילוֹת בִּבְרָכָה
- You are allowed to enter a bathroom while wearing a talit katan even though you are thus performing a mitzvah.
- The Shulchan Aruch (O.C.640:4) rules that if there is a foul odor in the succah you can sleep outside the succah. And the Shulchan Aruch (Rema O.C. 639:7) rules that when you are exempt from the succah, if you stay in the succah you are called a fool. The implication of this is that the only issue is that you were stringent when you need not have been, but not that there is any problem with actually performing a mitzvah in the presence of the foul odor.
- The Mishnah (Demai 1:4) states that one can tithe demai while naked. As explained by the Jerusalem Talmud (Demai 1:4), this is because no blessing is required. And this is codified by Rambam (Hilchot Ma'aser 9:4). Thus, we see that it is only a problem to make a blessing naked, but not to perform a mitzvah naked.
He also quotes a proof that he heard from a scholar: The Talmud (Kiddushin 32b) states that with regard to the commandment to rise for the elderly you might have thought that you even have to rise in a bathroom; therefore, the Torah used the term "you shall honor" to teach us that only a rising that confers honor is commanded, which excludes rising in a bathroom. Now if it was generally forbidden to perform a mitzvah in a bathroom, why would we need a special source by the mitzvah of rising for the elderly? Perforce, then, one may perform mitzvot in the bathroom.
R. Yosef Chaim, however, rejected this proof. He argued that it is possible that in general one may not perform a mitzvah in the bathroom, but perhaps there is an exception for a mitzvah that will pass by. Thus, without the special source by the case of rising for the elderly, you might have thought that you have to rise even in a bathroom since it is a mitzvah that will pass by.
The rejection of this proof is perhaps even stronger support for the case of sefirah in the bathroom, because since it is a mitzvah that will pass by you could do it in the bathroom even if in general it was forbidden to perform mitzvot in the bathroom.'
(Of course, all this assumes that our bathrooms are problematic in general like the bathrooms of old. However, some are of the opinion that our bathrooms do not have the status of "bathrooms", in which case there would be even more reason to permit sefirah if you are stuck there.)
Despite it being quite unlikely, but assuming it COULD happen, I understand that it wouldn't be possible to do it. First my question: Why would anybody wait until sunrise to count the omer? If someone wants yo perform a Mitswah, it would be as soon as possible, ergo, that would be as soon as you can count, not by the end of the space of time when possible (same principle as saying the Shmah of Arvit before 00:00 hours, even if you do it after in order to avoid the possibility of not doing it, although the Mishnah teaches that you can say Shmah at night until sunrise)
So back to business: 1. You can't say a Blessing IN the bathroom, since it's not proper to the Glory of HaShem. In fact, it's actually disrespectful, and you are to say the proper blessing before the Mitswah of counting the Omer.
- If it's disrespectful to Bless HaShem in the bathroom, even if you count without a blessing, you are keeping in mind a Mitswah "DeHoraitah" (from Torah itself), according to the most accredited rabbis of our age (Like Eliezer Melamed) you shouldn't even THINK of Torah while in the bathroom.
Therefore, I understand you just can't do such a thing