LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-12-2011, 08:09 PM   #1
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 289

Rep: Reputation: 10
Decrement using bash!!


Hi all,

Thanks in Advance!

I want a simple script to print today and yesterdays date.

using this command
Code:
date +%d%m%Y
i can able get today's date but i want yesterday's date with the same format.

so i tried using simple decrement operator


Code:
#!/bin/bash
DATE=`date +%d%m%Y`
x=$DATE
echo $((x--));
but it not works for me, i am quite new to bash scripting so is there any other way to solve this thread using bash means guide me to solve this thread.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 09-12-2011, 08:32 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
The date command is very flexible. You can just:
Code:
date -d 'yesterday' '+%d%m%Y'
 
2 members found this post helpful.
Old 09-12-2011, 08:42 PM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,899

Rep: Reputation: 4262Reputation: 4262Reputation: 4262Reputation: 4262Reputation: 4262Reputation: 4262Reputation: 4262Reputation: 4262Reputation: 4262Reputation: 4262Reputation: 4262
Quote:
Originally Posted by anishkumarv View Post
Hi all,
Thanks in Advance!

I want a simple script to print today and yesterdays date. using this command
Code:
date +%d%m%Y
i can able get today's date but i want yesterday's date with the same format. so i tried using simple decrement operator
Code:
#!/bin/bash
DATE=`date +%d%m%Y`
x=$DATE
echo $((x--));
but it not works for me, i am quite new to bash scripting so is there any other way to solve this thread using bash means guide me to solve this thread.
+1 for macemoneta solution.

OP, you don't ever seem to be doing any research on how to write scripts for yourself, or do any research on how to solve your own problems, but want people to write them for you:

http://www.linuxquestions.org/questi...e-line-901450/
http://www.linuxquestions.org/questi...ng-awk-896800/
http://www.linuxquestions.org/questi...script-896608/
http://www.linuxquestions.org/questi...ectory-894137/

Don't mean to sound nasty, but being spoon-fed every answer isn't a good way to learn. And you've been on LQ for over a year...'newbie' doesn't apply anymore.
 
Old 09-13-2011, 01:00 PM   #4
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 289

Original Poster
Rep: Reputation: 10
Hi TB0ne,

Thanks for your kindful words, i dont feel ashame never ever!! i know my values and goals, as a senior member i didnt expect from you, words are most harmful than bullets..hmmm days are not to far to become master in linux domain, Thanks for your Praising words.
 
0 members found this post helpful.
Old 09-13-2011, 01:19 PM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,899

Rep: Reputation: 4262Reputation: 4262Reputation: 4262Reputation: 4262Reputation: 4262Reputation: 4262Reputation: 4262Reputation: 4262Reputation: 4262Reputation: 4262Reputation: 4262
Quote:
Originally Posted by anishkumarv View Post
Hi TB0ne,
Thanks for your kindful words, i dont feel ashame never ever!! i know my values and goals, as a senior member i didnt expect from you, words are most harmful than bullets..hmmm days are not to far to become master in linux domain, Thanks for your Praising words.
Can't really understand what you're trying to say, but I really do hope you become a "master in linux domain". But you have to start learning on your own first, and doing basic research. If I had been using Linux for over a year, and had to ask others to write my scripts for me, or explain a man page....I WOULD be ashamed.

Again, I really am NOT trying to be nasty, but asking others to write your scripts or read man pages for you, isn't a good way to learn. Experiment. Try different things, and read/understand the errors, and move forward. THAT will get you knowledge.

Last edited by TB0ne; 09-14-2011 at 01:44 PM.
 
  


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
C programming increment and decrement doubt shariefbe Programming 3 05-26-2010 10:52 AM
How to achieve atomic increment/decrement in Linux silentray Programming 11 01-14-2010 06:33 AM
pam_mount login count doesn't decrement beaucoup Linux - Security 0 08-04-2005 11:08 PM
how to use fork/pipe to decrement a global varialbe Y and exit when Y is 0 keiwu Programming 1 02-19-2005 11:33 PM
why did bash 2.05b install delete /bin/bash & "/bin/sh -> bash"? johnpipe Linux - Software 2 06-06-2004 06:42 PM


All times are GMT -5. The time now is 10:52 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration