LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 03-24-2015, 05:21 PM   #1
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Rep: Reputation: 46
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
 
Old 03-24-2015, 05:30 PM   #2
Miati
Member
 
Registered: Dec 2014
Distribution: Linux Mint 17.*
Posts: 326

Rep: Reputation: 106Reputation: 106
put this at the top of the script

Code:
set -xv
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.
 
Old 03-24-2015, 05:45 PM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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
 
Old 03-24-2015, 06:29 PM   #4
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Original Poster
Rep: Reputation: 46
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
 
Old 03-24-2015, 07:26 PM   #5
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Original Poster
Rep: Reputation: 46
no joy on that had to use

unset var

Thanks again
 
Old 03-25-2015, 11:54 AM   #6
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Original Poster
Rep: Reputation: 46
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 == '' ]]
 
Old 03-25-2015, 12:03 PM   #7
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,790

Rep: Reputation: 2086Reputation: 2086Reputation: 2086Reputation: 2086Reputation: 2086Reputation: 2086Reputation: 2086Reputation: 2086Reputation: 2086Reputation: 2086Reputation: 2086
(()) is for numeric comparisons only. Use
Code:
[[ "$CURENTMONTH" == "Nisan" ]] && ((CURENTDAY > 15))
 
1 members found this post helpful.
Old 03-25-2015, 02:39 PM   #8
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Original Poster
Rep: Reputation: 46
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Upgrade to 2010 fail - "This build of Glib" messages in log rustiguzzi Mandriva 6 08-27-2010 04:05 PM
When can access("blah", R_OK) succeed and open("blah", O_RDONLY) fail? cyent Programming 3 08-03-2010 09:01 PM
Hardy won't startup, stops with a "fail" and I have to "ctrl+alt+del" to boot. brjoon1021 Ubuntu 10 12-15-2008 06:29 PM
startx fail , error shown "hostname: Unknown host " syseeker Red Hat 4 07-05-2006 11:40 AM
MA111 USB adapter driver "make config" fail theonlydrew Linux - Wireless Networking 1 01-26-2005 10:53 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration