LinuxQuestions.org
Review your favorite Linux distribution.
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 02-23-2018, 01:12 PM   #1
Andrey-Bushman
LQ Newbie
 
Registered: Feb 2018
Posts: 6

Rep: Reputation: Disabled
Question echo parameters


Hi all,

I've read `man echo`. I test how to work the `e` and `-E` parameters:

First case:
Code:
andrey@bush-hp ~ $ echo -e Bob\nJack\nMike >> foo
andrey@bush-hp ~ $ less foo
The result:
Quote:
BobnJacknMike
I expected to get it:
Code:
Bob
Jack
Mike
Second case:
Code:
andrey@bush-hp ~ $ echo -E Bob\nJack\nMike >> foo2
andrey@bush-hp ~ $ less foo2
The result:
Quote:
BobnJacknMike
I expected to get it:

Code:
Bob\nJack\nMike
I get the same result for both cases for the `\n` escape symbol. What is difference of these parameters?

Thank you
 
Old 02-23-2018, 01:21 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
You need to quote the string being echoed:
Code:
echo -e "Bob\nJack\nMike"
Bob
Jack
Mike
Incidentally, you can see the results of the echo command without redirecting to a file. It will just display for you.
 
Old 02-23-2018, 01:50 PM   #3
Andrey-Bushman
LQ Newbie
 
Registered: Feb 2018
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thank you!
 
Old 02-24-2018, 07:05 AM   #4
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
your shell has a builtin echo command - it is NOT /usr/bin/echo, and the man page does NOT apply.
try
Code:
help echo
instead.
 
Old 02-24-2018, 07:50 AM   #5
Andrey-Bushman
LQ Newbie
 
Registered: Feb 2018
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ondoho View Post
your shell has a builtin echo command - it is NOT /usr/bin/echo, and the man page does NOT apply.
try
Code:
help echo
instead.
Thank you, you are right:

Code:
andrey@bush-hp ~ $ type echo
echo is a shell builtin
 
Old 02-24-2018, 08:32 AM   #6
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
If I am not mistaken, if you don't quote the string, the \n is interpreted by the shell, not by echo.

jlinkels
 
  


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
edit a file /etc/fstab , what parameters can be changebale and which parameters lenin99 Debian 7 01-24-2017 04:03 AM
trying to echo a line that contains echo in a file aristosv Linux - Software 7 01-05-2016 12:39 PM
[SOLVED] Why there are two separate parameters in /proc/sys/net/ipv4/ for security parameters gprathap1121@gmail.com Linux - Security 4 07-14-2014 12:41 AM
grep | xargs -I echo $(foo; bar; echo $(fee; fi; fo; fum)) == questionable output.. GrapefruiTgirl Programming 11 12-07-2010 07:02 PM
ls | echo, I got blank, why can't echo take the 2nd seat in a pipeline? elinuxqs Linux - Newbie 6 11-24-2006 08:25 AM

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

All times are GMT -5. The time now is 03:56 AM.

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