Solved

need to get 2 character day from date all the time

Posted on 2006-07-05
7
299 Views
Last Modified: 2011-10-03
gfs1 Jax:alex /home/alex> CDA=`date | cut -c9-10`                
gfs1 Jax:alex /home/alex> echo $CDA                              
5                                                                
gfs1 Jax:alex /home/alex>                                        

Thanks in advance,
-Alex
0
Comment
Question by:AlexF777
  • 3
  • 2
  • 2
7 Comments
 
LVL 1

Accepted Solution

by:
bengtbj earned 100 total points
ID: 17042873
OK, you have two options.

One, use date formating
> CDA=`date +%d`
That will return day of moth with two didgits
(So today 05 :) )
 
otherwise you could use
CDA=date | cut -c9-10`
printf "%02s"
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 100 total points
ID: 17046247
CDA=`printf "%02d" \`date +%d\``
0
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 50 total points
ID: 17052791
Tintin with a bash only solution ;-)
I'd vote for:
CDA=`date +%d`
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 100 total points
ID: 17069349
ahoffman.

Doesn't matter if you are using bash, ksh, sh or zsh.

CDA=`date +%d`

is not going to give you a zero padded 2 digit date.
0
 
LVL 1

Assisted Solution

by:bengtbj
bengtbj earned 100 total points
ID: 17071305
Tintin:

From date's man pages

%d Displays the day of the month as a decimal number (01-31). In a two-digit
field, a 0 is used as leading space fill.

However, some shells might remove the leading zero, in that case you could try
CDA="`date +%d`"
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17071332
Tintin, which OS's date does not use leading zeros (I'm learning too)
0
 
LVL 48

Expert Comment

by:Tintin
ID: 17077251
Doh!  What was I thinking!!  Not sure how I got on to that line of thought.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now