Confused by bash script fail
Ladies & Gents,
I have a script that processes a daily count up to fifty days and generates a text-to-speach file which it then schedules to run at a specific time. Last year this script worked fine. Did thy make a change to bash that would cause this code to fail? Code:
if [[ "$CURENTMONTH" == "Nisan" ]] && (( "$CURENTDAY" > 15 ));then Shellcheck.net detects no error. Thanks |
Need More Data.
That line is not a script.
Can you provide more of the script please? At the very least, the lines where the variables referenced in that command are set. It makes sense that the second condition will not be evaluated IF th first condition returns false. That is expected behavior, sine the value of the second condition is not NEEDED if the first one is false. Also, the LANG and TIMEZONE settings may help. Does your script do any logging so you can check the values of the variables when execution reaches that point? IF not, you may want to add some logging to make troubleshooting easier. FYI: While it is not invalid, I would never structure the condition quite that way. I use the number of the month, rather than the name, so textual changes in the way the name string is presented will not break the script. That may, or may not apply, depending upon how you are setting the month in the Jewish calendar into the environment. Also, in the second condition you compare a string to a number. The shell is smart enough that this will generally work as you would expect, but there are more correct techniques. ( This last is not an issue with the current case, if the second is not being evaluated anyway. I just wanted to mention it. ) |
Thanks wpeckham,
The actual code section Code:
function Count_Omer { Code:
+ Count_Omer |
It looks like both CURRENTMONTH and CURRENTDAY have a leading newline character, and the string "\nNisan" doesn't match "Nisan". Since you're using the numeric conversion of CURRENTDAY, that leading whitespace character probably doesn't matter, but for the string comparison it does. It is not apparent to me where that newline character came from. It must have something to do with your locale settings.
|
We would probably need to see the output from hdate to see why awk is returning an additional newline prior to its value, but based on the presented code, I also see no reason for the additional character.
The locale settings would also be worth a check ... but one would think you know if you changed those? |
Untested, but does the following work?
Code:
if (( "$CURENTMONTH" == "Nisan" && "$CURENTDAY" > 15 ));then |
@norobro - Your example will fail for multiple reasons, the first being that (()) only tests numeric values so the first test will throw an error and secondly for the reasons mentioned that the leading
newline will still make the text comparison fail (even if it could work) |
:redface: As you can tell, I don't do much bash scripting.
Edit: From the screenshots on the libhdate webpage (http://libhdate.sourceforge.net/?q=node/3) it looks like the line feed is a feature. They pipe output to column to get rid of it but you can test for an empty field in awk: Code:
awk '$6!="" {print $6}' |
No I have not changes the local settings. This is running on Debian Testing.
The output from hdate. Code:
:~$ hdate -q --not-sunset-aware 22 04 2016|awk '{print $5;}' Code:
:~$ hdate -q --not-sunset-aware 22 04 2016|awk '$5!="" {print $5;}' |
Please post the output from these commands:
Code:
locale |
Code:
:~$ locale |
Does not look like a locale problem. If hdate does not have any latitude longitude or UTC offset inputs it adds a linefeed regardless of the -q (suppress warnings) or sending stderr to /dev/null
You could either strip the linefeed using any sort of string function or include the missing options. Quote:
|
Strange. It gets rid of the LF on my machine:
Code:
$ hdate -q --not-sunset-aware 22 04 2016 |
Difference in versions?
|
Thanks All
norobro, not sure why it did not remove it the first time I ran it, but after I ran the commands to supply the requested info it started working. michaelk, you are correct, adding in the long & lat and time zone data caused it to not generate the line feed. So which is the better option? |
All times are GMT -5. The time now is 12:16 AM. |