LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Decrement using bash!! (https://www.linuxquestions.org/questions/linux-newbie-8/decrement-using-bash-902673/)

anishkumarv 09-12-2011 08:09 PM

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.

macemoneta 09-12-2011 08:32 PM

The date command is very flexible. You can just:
Code:

date -d 'yesterday' '+%d%m%Y'

TB0ne 09-12-2011 08:42 PM

Quote:

Originally Posted by anishkumarv (Post 4470156)
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.

anishkumarv 09-13-2011 01:00 PM

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.

TB0ne 09-13-2011 01:19 PM

Quote:

Originally Posted by anishkumarv (Post 4470767)
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.


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