hurnhu
hurnhu

Reputation: 936

how to echo before running a command, shell script

i am making a shell script that will echo my name, and then echo "the date today is" and run date. but when it runs date it erases "the date today is" ive also tried not having the pipe, and having the date command on the next line. but both of those do not work the way i am looking for.

#Michael LaPan
#3/19/2014
clear
echo Michael LaPan
echo "the date today is:" | date

right now it just looks like

Michael LaPan
Wed Mar 19 19:40:53 EDT 2014

how i want it to look

Michael LaPan
 the date today is: Wed Mar 19 19:40:53 EDT 2014

Upvotes: 0

Views: 589

Answers (4)

Ritesh Prajapati
Ritesh Prajapati

Reputation: 983

You can use following command to get date which you want

echo -n "the date today is:"; date

Upvotes: 0

Nicola Musatti
Nicola Musatti

Reputation: 18218

This also works:

echo "The date today is: " `date`

This should work all the way back to 7th Edition Unix. I never laid my hands on anything earlier.

Upvotes: 0

kai
kai

Reputation: 378

What you are looking for is shell command expansion operator or $().

Try:

echo "the date today is: `date`"

or

echo "the date today is: $(date)"

Upvotes: 6

William Pursell
William Pursell

Reputation: 212248

Try:

echo -n "the date today is:" ; date

By piping the output of echo to date, you are effectively discarding it, since date ignores it. By running them serially, the output of both echo and date go to the output of the script. Use -n to suppress the newline that would otherwise appear.

Upvotes: 2

Related Questions