LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 11-15-2020, 01:52 PM   #1
akira1412
LQ Newbie
 
Registered: Nov 2020
Posts: 3

Rep: Reputation: Disabled
printf (is "+" in the argument is an add or concatenation)


Hi there, I'm still a newbie in using terminal. Hope somebody can help......I'm quite confused does "+" mean concatenate the date or add days into date?

printf '\nIn 2007, %s \n\n' "$(date -d" 2007-09-01 17:30:24.000000000 UTC +
$(( 36 /60 /60 /24 / 2 )) days" '+%d %B')"
 
Old 11-15-2020, 02:20 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,732

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
In the example posted, the 1st + sign is part of the argument to the date command...has naught to do with printf...see man date
I’d have to check man printf about the second + sign to be sure, but I’d guess it’s concatenation.

A good way to figure out things like this is to run each command separately to see what each part does.

Last edited by scasey; 11-15-2020 at 02:24 PM.
 
Old 11-16-2020, 01:22 AM   #3
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
This is not SOLVED. Would OP like to clarify?
 
Old 11-16-2020, 02:27 AM   #4
akira1412
LQ Newbie
 
Registered: Nov 2020
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ondoho View Post
This is not SOLVED. Would OP like to clarify?
Urmm...does it mean its not the answer to my question??
 
Old 11-16-2020, 03:27 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,879

Rep: Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317
Quote:
Originally Posted by akira1412 View Post
Urmm...does it mean its not the answer to my question??
it is your question/thread. You can decide if it was answered/solved. What do you think?
 
Old 11-16-2020, 04:25 AM   #6
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
The first '+' means add days to the date specified. The second '+' introduces the output format specifier of the date command. I don't know why they chose to write date to work that way instead of just making the output format a switch argument like the others, but it is what it is. Both are arguments to date and have nothing to do with printf.

Here's a broken down example that might help you understand what's going on.
Code:
basedate="2007-09-01 17:30:24.000000000 UTC"
days=200

display_date=$(date -d "$basedate + $days days" '+%Y %d %B')

printf 'In %s, %s %s\n' $display_date
Your days calculation made no sense, so I replaced it with '200', and I removed the hardcoded year in your printf format string and replaced it with an additional output field from date, for reasons that should be obvious.


P.S. Odd choice of basedate, but whatever rocks your boat.
 
2 members found this post helpful.
Old 11-16-2020, 07:14 AM   #7
akira1412
LQ Newbie
 
Registered: Nov 2020
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thumbs up

Quote:
Originally Posted by GazL View Post
The first '+' means add days to the date specified. The second '+' introduces the output format specifier of the date command. I don't know why they chose to write date to work that way instead of just making the output format a switch argument like the others, but it is what it is. Both are arguments to date and have nothing to do with printf.

Here's a broken down example that might help you understand what's going on.
Code:
basedate="2007-09-01 17:30:24.000000000 UTC"
days=200

display_date=$(date -d "$basedate + $days days" '+%Y %d %B')

printf 'In %s, %s %s\n' $display_date
Your days calculation made no sense, so I replaced it with '200', and I removed the hardcoded year in your printf format string and replaced it with an additional output field from date, for reasons that should be obvious.


P.S. Odd choice of basedate, but whatever rocks your boat.
Thank you so much..... now I understand
 
  


Reply



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
[SOLVED] printf $"Hello $var\n" vs. printf "Hello $var\n" -- not a typo. What is it? GrapefruiTgirl Programming 2 10-21-2010 08:21 AM
printf( "Hello %s\n", "World" ) megacoder LinuxQuestions.org Member Intro 1 09-29-2010 11:16 AM
csh Shell Script: String Concatenation, how do i add a new line character? vxc69 Programming 1 05-04-2009 07:51 PM
Help With Java Problem Please"""""""""""" suemcholan Linux - Newbie 1 04-02-2008 06:02 PM
How is 'man 3 printf' different from 'man printf' ?? purpleburple Linux - General 3 09-23-2002 12:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:56 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
Open Source Consulting | Domain Registration