I am new to terminal and trying to learn how to use it.
What do these lines do? And how do they work?
echo -n "Today's date is: "
date +"%A, %B %-d, %Y"
bashcommand linedatescriptssyntax
I am new to terminal and trying to learn how to use it.
What do these lines do? And how do they work?
echo -n "Today's date is: "
date +"%A, %B %-d, %Y"
Best Answer
meaning, the
echo
command is part of thebash
program itself (assuming you use bash)-n
is an option, so let's see what it doesSo when we run the line:
Hmm that doesn't look very good, because there's no newline after the printed text. We'll come back to this.
ah so the
date
command is a separate program. What does it do?The characters after the
date
command are format options (which must be preceded by+
) - different parts of the date are specified (for example%A
is the full name of the day of the week - see the rest ofman date
for the complete list of options)So if we put the commands together in a script and then run the script we will get
Nice! If you want the same effect in a terminal, you can use a semicolon to separate the two commands instead of a newline: