- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- echo with NO new line option
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-07-2007 09:38 AM
тАО01-07-2007 09:38 AM
I have an apparently simple question...but I don't resolve it anyway!
I want to make a simple script:
#!/sbin/sh
touch file.txt
echo -n "first line" >> file.txt
echo "second line" >> file.txt
this script write a file with 2 TWO lines...but I want to write a single line with two different echo command.
I know that echo -n doesn't write the new line at the end of the command but...it does!!
So...the -n option doesn't work...and even the \n option...so how can I write a single line?
Thanks in advance to anybody!
Emanuele
Solved! Go to Solution.
- Tags:
- echo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-07-2007 10:55 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-07-2007 04:05 PM
тАО01-07-2007 04:05 PM
Re: echo with NO new line option
Hassel suggested very correct. Actually it is correct that you are using -n option, but this option is not working with all the unix environment.
Also if you want to feed extra line, you can use \n option.
Like
echo "Test \n"
Regards
Nitin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-07-2007 04:05 PM
тАО01-07-2007 04:05 PM
Re: echo with NO new line option
Hassel suggested very correctly. Actually it is correct that you are using -n option, but this option is not working with all the unix environment.
Also if you want to feed extra line, you can use \n option.
Like
echo "Test \n"
Regards
Nitin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-08-2007 12:09 AM
тАО01-08-2007 12:09 AM
Re: echo with NO new line option
best is NOT to use 'echo' but the posix shell builting 'print' - this will work across all platforms:
print -n string1 string2
will NOT append a newline.
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-08-2007 10:17 AM
тАО01-08-2007 10:17 AM
Re: echo with NO new line option
was to test "echo" to see how it works:
echo -n x | grep n > /dev/null
If "-n" works, the status is non-zero. If
"-n" does not work, it's zero.
td176> uname -a
HP-UX td176 B.11.23 U ia64 1928826293 unlimited-user license
td176> echo -n x
-n x
td176>
td176> echo -n x | grep n > /dev/null ; echo $?
0
urtx# sizer -v
Compaq Tru64 UNIX V5.1B (Rev. 2650); Thu Nov 23 02:10:08 CST 2006
urtx# echo -n x
xurtx#
urtx# echo -n x | grep n > /dev/null ; echo $?
1
When your script knows what works, it can
define an alias or a function to do whatever
works. (Years ago, I named mine "echn".) As
usual, there are many ways to solve a problem
like this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-08-2007 09:33 PM
тАО01-08-2007 09:33 PM
Re: echo with NO new line option
A real POSIX shell or echo doesn't support -n.
- Tags:
- scummy C shell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-09-2007 03:22 AM
тАО01-09-2007 03:22 AM
Re: echo with NO new line option
I was wrong because I put the \c out of "".... :-)
Thanks to everybody
Emanuele