Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
03-24-2015, 05:21 PM
|
#1
|
Member
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921
Rep:
|
if [[ -n "$1" ]]; then FAIL FAIL FAIL
Ladies & Gents
Thanks for your patients with my old slow learning brain.
I have not been able to figure out why this fails.
if [[ -n "$1" ]]; then I have also tried
if [[ -z "$1" ]]; then which only fails the other way.
The variable $1 is the first passed into the function this is part of and contains something like 20:34 which is a time that is used in a different function to schedule an "at" job.
The line above needs to "add" or "omit" some text that is dumped into a file for latter processing based on if this time data exists or not. Because it fails the whole function fails to generate the proper files. :Grrrrr:
In a different part of the larger project there in an almost identical line that works just fine.
if [[ -n "$YOMTOVE" ]]; then
The only difference that I know of is that this one has words in the variable like "Pesach" and the other one has the time as I mentioned before.
Any idea's
thanks
|
|
|
03-24-2015, 05:30 PM
|
#2
|
Member
Registered: Dec 2014
Distribution: Linux Mint 17.*
Posts: 326
Rep: 
|
put this at the top of the script
Then post the output relevant to if [[ -n "$1" ]];
It should preface with a +
It'll show what is actually being compared so there's less guessing on what is being compared.
|
|
|
03-24-2015, 05:45 PM
|
#3
|
LQ Guru
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573
|
Works fine for me...
Code:
$ var="20:34"
$ if [[ -n "$var" ]]; then echo 1; fi
1
$ if [[ -z "$var" ]]; then echo 1; fi
$ var=""
$ if [[ -n "$var" ]]; then echo 1; fi
$ if [[ -z "$var" ]]; then echo 1; fi
1
|
|
|
03-24-2015, 06:29 PM
|
#4
|
Member
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921
Original Poster
Rep:
|
I found the issue. The variable is not being unset as I thought it would in the calling loop. It occurred to me while I was eating dinner. Checked it out an sure enough that's it. Now all I have to do is figure out the best way to do it.
Can I pass it in like the red text making it unset?
The offending code:
Code:
# Set up the Omer count
# needs LONG LAT TZ CITY STATE ZIP passed in
function Count_Omer {
CURENTDAY=$( hdate -q --not-sunset-aware $DAY $MONTH $YEAR|awk '{print $5;}' )
CURENTMONTH=$( hdate -q --not-sunset-aware $DAY $MONTH $YEAR|awk '{print $6;}' )
echo "$CURENTDAY $CURENTMONTH"
if echo $CURENTMONTH | grep -e Nisan -e Iyyar -e Sivan ;then
if (( "$CURENTMONTH" == "Nisan" && "$CURENTDAY" > 15 ));then
OMER=$(hdate -oq $DAY $MONTH $YEAR | awk 'NR==3'|awk '{print $4}')
MORNOMER="$(hdate -t -L$LONG -l$LAT -z$TZ $DAY $MONTH $YEAR | awk '/sunrise/{print $2}')"
Omer_Blessing "$EVEOMER=""" "$OMER" "${OMER}_Omer_Morning"
at "$MORNOMER" "$MONTH/$DAY/$YEAR" -f "$TMPDIR"/${OMER}_Omer_Morning
EVEOMER="$(hdate -t -L$LONG -l$LAT -z$TZ $DAY $MONTH $YEAR | awk '/sunset/{print $2}')"
Omer_Blessing "$EVEOMER" "$OMER" "${OMER}_Omer_Evening"
at "$EVEOMER" "$MONTH/$DAY/$YEAR" -f "$TMPDIR"/${OMER}_Omer_Evening
return
elif (( "$CURENTMONTH" == "Iyyar" ));then
OMER=$(hdate -oq $DAY $MONTH $YEAR | awk 'NR==3'|awk '{print $4}')
MORNOMER="$(hdate -t -L$LONG -l$LAT -z$TZ $DAY $MONTH $YEAR | awk '/sunrise/{print $2}')"
Omer_Blessing "$EVEOMER" "$OMER" "${OMER}_Omer_Morning"
at "$MORNOMER" "$MONTH/$DAY/$YEAR" -f "$TMPDIR"/${OMER}_Omer_Morning
EVEOMER="$(hdate -t -L$LONG -l$LAT -z$TZ $DAY $MONTH $YEAR | awk '/sunset/{print $2}')"
Omer_Blessing "$EVEOMER" "$OMER" "${OMER}_Omer_Evening"
at "$EVEOMER" "$MONTH/$DAY/$YEAR" -f "$TMPDIR"/${OMER}_Omer_Evening
return
elif (( "$CURENTMONTH" == "Sivan" && "$CURENTDAY" < 6 ));then
OMER=$(hdate -oq $DAY $MONTH $YEAR | awk 'NR==3'|awk '{print $4}')
MORNOMER="$(hdate -t -L$LONG -l$LAT -z$TZ $DAY $MONTH $YEAR | awk '/sunrise/{print $2}')"
Omer_Blessing "$EVEOMER" "$OMER" "${OMER}_Omer_Morning"
at "$MORNOMER" "$MONTH/$DAY/$YEAR" -f "$TMPDIR"/${OMER}_Omer_Morning
EVEOMER="$(hdate -t -L$LONG -l$LAT -z$TZ $DAY $MONTH $YEAR | awk '/sunset/{print $2}')"
Omer_Blessing "$EVEOMER" "$OMER" "${OMER}_Omer_Evening"
at "$EVEOMER" "$MONTH/$DAY/$YEAR" -f "$TMPDIR"/${OMER}_Omer_Evening
return
else
return
fi
else
return
fi
}
Thanks
|
|
|
03-24-2015, 07:26 PM
|
#5
|
Member
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921
Original Poster
Rep:
|
no joy on that had to use
unset var
Thanks again
|
|
|
03-25-2015, 11:54 AM
|
#6
|
Member
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921
Original Poster
Rep:
|
Well It seams that I lied about having the problem solved.  After I added this piece into the larger project and tried to run it, it still fails.
So here is the code that is failing
Code:
unction Count_Omer {
CURENTDAY=$( hdate -q --not-sunset-aware $DAY $MONTH $YEAR|awk '{print $5;}' )
CURENTMONTH=$( hdate -q --not-sunset-aware $DAY $MONTH $YEAR|awk '{print $6;}' )
echo "$CURENTDAY $CURENTMONTH"
if echo $CURENTMONTH | grep -e Nisan -e Iyyar -e Sivan ;then
if (( "$CURENTMONTH" == "Nisan" && "$CURENTDAY" > 15 ));then
OMER=$(hdate -oq $DAY $MONTH $YEAR | awk 'NR==3'|awk '{print $4}')
MORNOMER="$(hdate -t -L$LONG -l$LAT -z$TZ $DAY $MONTH $YEAR | awk '/sunrise/{print $2}')"
Omer_Blessing "$EVEOMER" "$OMER" "${OMER}_Omer_Morning"
at "$MORNOMER" "$MONTH/$DAY/$YEAR" -f "$TMPDIR"/${OMER}_Omer_Morning
EVEOMER="$(hdate -t -L$LONG -l$LAT -z$TZ $DAY $MONTH $YEAR | awk '/first_stars/{print $2}')"
Omer_Blessing "$EVEOMER" "$OMER" "${OMER}_Omer_Evening"
at "$EVEOMER" "$MONTH/$DAY/$YEAR" -f "$TMPDIR"/${OMER}_Omer_Evening
unset EVEOMER
unset MORNOMER
return
elif (( "$CURENTMONTH" == "Iyyar" ));then # Should fail here
OMER=$(hdate -oq $DAY $MONTH $YEAR | awk 'NR==3'|awk '{print $4}')
MORNOMER="$(hdate -t -L$LONG -l$LAT -z$TZ $DAY $MONTH $YEAR | awk '/sunrise/{print $2}')"
Omer_Blessing "$EVEOMER" "$OMER" "${OMER}_Omer_Morning"
at "$MORNOMER" "$MONTH/$DAY/$YEAR" -f "$TMPDIR"/${OMER}_Omer_Morning
EVEOMER="$(hdate -t -L$LONG -l$LAT -z$TZ $DAY $MONTH $YEAR | awk '/first_stars/{print $2}')"
Omer_Blessing "$EVEOMER" "$OMER" "${OMER}_Omer_Evening"
at "$EVEOMER" "$MONTH/$DAY/$YEAR" -f "$TMPDIR"/${OMER}_Omer_Evening
unset EVEOMER
unset MORNOMER
return
elif (( "$CURENTMONTH" == "Sivan" && "$CURENTDAY" < 6 ));then
OMER=$(hdate -oq $DAY $MONTH $YEAR | awk 'NR==3'|awk '{print $4}')
MORNOMER="$(hdate -t -L$LONG -l$LAT -z$TZ $DAY $MONTH $YEAR | awk '/sunrise/{print $2}')"
Omer_Blessing "$EVEOMER" "$OMER" "${OMER}_Omer_Morning"
at "$MORNOMER" "$MONTH/$DAY/$YEAR" -f "$TMPDIR"/${OMER}_Omer_Morning
EVEOMER="$(hdate -t -L$LONG -l$LAT -z$TZ $DAY $MONTH $YEAR | awk '/first_stars/{print $2}')"
Omer_Blessing "$EVEOMER" "$OMER" "${OMER}_Omer_Evening"
at "$EVEOMER" "$MONTH/$DAY/$YEAR" -f "$TMPDIR"/${OMER}_Omer_Evening
unset EVEOMER
unset MORNOMER
return
else
echo "No Count today"
return
fi
else
echo "Not Spring"
return
fi
}
And the debug with some comments I added:
Code:
+ Count_Omer
++ hdate -q --not-sunset-aware 25 03 2015
++ awk '{print $5;}'
+ CURENTDAY='
5'
++ hdate -q --not-sunset-aware 25 03 2015
++ awk '{print $6;}'
+ CURENTMONTH='
Nisan'
+ echo '
5
Nisan'
5 # Hebrew day
Nisan # Hebrew Month
+ echo Nisan
+ grep -e Nisan -e Iyyar -e Sivan
Nisan
+ ((
Nisan == Nisan && # pass
5 > 15 )) # Hebrew day less than 15 = fail
+ ((
Nisan == Iyyar )) # Hebrew months not the same, should fail but dosen't
++ hdate -oq 25 03 2015
++ awk NR==3
++ awk '{print $4}'
+ OMER=
++ hdate -t -L-85.9588 -l41.7381 -z-4 25 03 2015
++ awk '/sunrise/{print $2}'
+ MORNOMER=07:40
+ Omer_Blessing '' '' _Omer_Morning
+ week=(7 14 21 28 35 42 49)
+ omer=(1 2 3 4 5 6)
+ [[ -z '' ]]
+ echo 'We don'\''t say the blessing durring the daylight hours'
We don't say the blessing durring the daylight hours
+ Element_In '' 1 2 3 4 5 6
+ local e
+ for e in '"${@:2}"'
+ [[ 1 == '' ]]
|
|
|
03-25-2015, 12:03 PM
|
#7
|
Senior Member
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,820
|
(()) is for numeric comparisons only. Use
Code:
[[ "$CURENTMONTH" == "Nisan" ]] && ((CURENTDAY > 15))
|
|
1 members found this post helpful.
|
03-25-2015, 02:39 PM
|
#8
|
Member
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921
Original Poster
Rep:
|
Thanks ntubski
That did the trick. I think I only have one left. Think being the operative word. Also the variable issue I was having in a different thread, I did not need not need to export them.
Thanks again for all your kindness
|
|
|
All times are GMT -5. The time now is 06:21 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|