How to test the current days to compare a given day?

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to test the current days to compare a given day?
# 1  
Old 10-17-2016
How to test the current days to compare a given day?

Hi,

I tested this :
Code:
#!/bin/bash
set +x

CurrentDay=$(date +'%a') (Fri) on my server
Fri=$(date -d "Friday" | awk '{print $1}')
Sat=$(date -d "Saturday" | awk '{print $1}')

if [[ $CurrentDay == "$Sat" ]] ; then echo "ok" ; else echo "ok" ; fi

But the output tell me always "ok" why?! Thanks in advance Smilie
# 2  
Old 10-17-2016
Because your else says Ok too...

Regards...
# 3  
Old 10-17-2016
OMG, I go out ! I hang me SmilieSmilieSmilie

Thanks Smilie
# 4  
Old 10-17-2016
Hello Arnaudh78,

Off course if you have a coin whose both sides are either heads or tails then it will be each time heads or tails(depending which one you have both the sides). Your code tells in if statement if condition is TRUE then print ok and when it is NOT true means go to elsethen also print ok, so that only it is printing each time the same. Try changing it to NOT ok etc. Let us know if you have any queries on same.

Thanks,
R. Singh
# 5  
Old 10-17-2016
Quote:
Originally Posted by RavinderSingh13
Hello Arnaudh78,

Off course if you have a coin whose both sides are either heads or tails then it will be each time heads or tails(depending which one you have both the sides). Your code tells in if statement if condition is TRUE then print ok and when it is NOT true means go to elsethen also print ok, so that only it is printing each time the same. Try changing it to NOT ok etc. Let us know if you have any queries on same.

Thanks,
R. Singh
I made a big stupid mistake of inattention sorry...
# 6  
Old 10-17-2016
Quote:
Originally Posted by Arnaudh78
I made a big stupid mistake of inattention sorry...
Hello Arnaudh78,

You need not to be sorry, we all are human beings, we learn and go forward. Need not to worry, just enjoy learning Smilie

Thanks,
R. Singh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to save current day files only?

i want to save current day file daily for this is am using below command. cp -p $(ls -lrt | grep "Apr 15" | awk '{print $9}' in order to script this part, i am saving date output in a file using below command date | awk '{print $2,$3}' >>t1 thru below command i want to list the file of... (7 Replies)
Discussion started by: scriptor
7 Replies

2. Shell Programming and Scripting

To get Non matching records for current day

My objective is to get the non matching records of previous day with current day. eg, file1 contains 1 a 2 b and file2 contains: 2 b 3 c then expected output is 3 c¨ another example file 1 contains: 1 a 2 b file 2 contains 1 c 2 b (8 Replies)
Discussion started by: newbie2014
8 Replies

3. Shell Programming and Scripting

Number of days in current month

I have a homework assignment: ---------------------------------------- "Display" the number of days in the current month. For example: September 1996 has 30 days ---------------------------------------- I am trying to just display the head of cal to start the sentence. eg. cal | head ... (1 Reply)
Discussion started by: eaafuddy
1 Replies

4. Shell Programming and Scripting

Can i get the previous/next days date of a selected day

Ok, the title is confusing i know, but it is a weird question. I have a bash script running on Centos5.8 and want to find a better way to do some date manipulation. What i am trying to do is get 3 days of files (day before, that day, and day after), concatenate the three files and pass them on... (2 Replies)
Discussion started by: oly_r
2 Replies

5. UNIX for Dummies Questions & Answers

Move the files between Current day & a previous day

Hi All, I have a requirement where I need to first capture the current day & move all the files from a particular directory based on a previous day. i.e move all the files from one directory to another based on current day & a previous day. Here is what I am trying, but it gives me errors.... (2 Replies)
Discussion started by: dsfreddie
2 Replies

6. IP Networking

network connection dying after an uptime of a day or two days

hie guys I am running fedora 6 on remote machines which are connecting to my server. The remote machines connect through one machine (more like my router) to the server. The problem i am having is that the remote machines are suppose to be reporting in real time mode to the server. Most of these... (2 Replies)
Discussion started by: no3more
2 Replies

7. Shell Programming and Scripting

Searching for files over 30 days old in current directory

May be a simple question for experts here.... I need to get the list of files older than 30 days in the current folder. I tried "find", but it searches recursively in all the sub directories. Can I restrict the recursive search and extract the files only from current directory ? (18 Replies)
Discussion started by: cxredd4
18 Replies

8. Shell Programming and Scripting

subtracting a days from current date

Hi i am trying to subtract days from current date. For example todays date is 10/03/2006. If i subtract 2 days it should give 8/03/2006. I am also trying to find the access date of a file in dd/mm/yyyy format. Can any one please help in how to do this. Ramesh (1 Reply)
Discussion started by: rameshspal
1 Replies

9. UNIX for Dummies Questions & Answers

I want to get day from the current system date

Hi, I want to check what day is today (like mon,Tue,wed) When i checked the syntax, i dont see there is a format specifier for getting the day. Let me know how to get the same. I am very new to unix and so I am asking some basic questions. cheers, gops (2 Replies)
Discussion started by: gopskrish
2 Replies

10. Shell Programming and Scripting

How to compare prev day file to current day file

Hi all: I am new to this board and UNIX programming so please forgive if I don't explain something correctly. I am trying to write a script to keep track of our links, we link one program written for Client A to Client B's directory. What we want to do is to keep track of our linked programs... (1 Reply)
Discussion started by: Smurtzy
1 Replies
Login or Register to Ask a Question