ProgrammingThis 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.
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.
I am having issues getting dates converted. Note that I am not a programmer. Please don't laugh at what I have. It is the best I can do with copy/paste. A friend of mine wrote what I copied off for me for the start of the project. But I hate to keep bugging him with my small issues.
The first part of the script that is failing.
It looks like this
Code:
# Tempoary Variables
BDay=17
BMonth=09
BYear=1956
#step 1 convert civil birthday to hebrew birthday
HBDate=`hdate -q ${BDay} ${BMonth} ${BYear}`
# gives
# "a blank line"
#Friday, 17 September 1965, 20 Elul 5725
echo " #1 $HBDate"
#step 2 seperate output from above into
# HBDay = Hebrew Birth Day
# HMonth = Hebrew Birth Month
# HBYear = Hebrew Birth Year
HBlocData=`echo ${HBDate} | awk -F"," '{printf("%s",$3)}'`
HBDay=`echo ${HBlocData} | awk -F"," '{printf("%s",$1)}' | sed s/\ //g`
if [ `echo ${HBlocData} | awk NF = 4` ]; then
HMonth=`echo ${HBlocData} | awk -F"," '{printf("%s",$2 $3)}' | sed s/\ //g`;
HBYear=`echo ${HBlocData} | awk -F"," '{printf("%s",$4)}' | sed s/\ //g`;
elif [ `echo ${HBlocData} | awk NF = 3` ]; then
HMonth=`echo ${HBlocData} | awk -F"," '{printf("%s",$2)}' | sed s/\ //g`;
HBYear=`echo ${HBlocData} | awk -F"," '{printf("%s",$3)}' | sed s/\ //g`;
fi
echo "#2 $HBDay"
echo "$HMonth"
echo "$HByear"
My guess is that the awk/sed part is not working the way I want. I tried to change it to what I needed but clearly it is not right.
It fails with
Code:
awk: fatal: cannot open file `=' for reading (No such file or directory)
I gather that my code is expecting a number not a word and it does not know how to deal with that. The reason for the test is that on a leap year we have Adar I and Adar II.
I have tried removing the "sed" part with no joy. Even the day variable is not being populated. I have tried adding and removing the " in the sed line. no Joy.
First of all, fix the lines .. you hava $HBlocData} when you should have ${HBlocData}... Pay close attention to symbols on your output... It's normal to have typos, but the output will usually point them out..
Second, please provide the full script at any point you have problems since, for example, right now the output indicates some weird quotes.. And if we decide to take a closer look at your script we would like and probably be required to run it locally to figure out what the problem is..
Last edited by Smokey_justme; 09-29-2014 at 05:38 AM.
./blessingStart.sh: line 30: [: Tishrei: binary operator expected
You were trying to use the "[" command to check if awk's output was non-empty, but the output was split into multiple arguments which "[" can't handle. Use quotes to avoid word splitting:
Code:
if [ -n "`echo ${HBlocData} | awk 'NF == 4'`" ]; then
The -n option tells "[" to test for non-empty string (that's what it does when given a single string, but it's usually better to be explicit).
I think this is the last problem with this part of the script.
After changing the temporary variables at the beginning of the script to get a leap-year using
Code:
# Tempoary Variables
BDay=17
BMonth=2
BYear=2016
I get a fail with
Code:
v$ ./blessingStart.sh
#1
Wednesday, 17 February 2016, 8 Adar I 5776
8 Adar I 5776
#2 8
AdarI
5776
+ case ${HMonth} in
+ echo 'Invalid Month'
Invalid Month
+ exit
As you can see if falls trough the test for "Adar I" and "Adar II" to *) invalid....
Can anybody point me at how to fix this without using if;then ?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.