echo "\n" > /tmp/tmp
I tried the above example. But I get the string '\n' (literally) in
the file.
printf "\n" >/tmp/tmp
--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
Barry gave you one solution.
You can also try
echo >/tmp/tmp
or
echo -e '\n' >/tmp/tmp
Note that echo is not only a binary, but it is also a shell builtin command.
Also note that the echo binary has several system-dependant variations, and
not all handle the (implicit) newline in the same way.
--
Lew Pitcher
Master Codewright & JOAT-in-training | Registered Linux User #112576
Me: http://pitcher.digitalfreehold.ca/ | Just Linux: http://justlinux.ca/
---------- Slackware - Because I know what I'm doing. ------
command "
"
-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet...@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
What I want is to pass an newline character as an argument to any
program.
I made the following C++ program.
$ cat main.cc
#include <iostream>
int main(int argc, char *argv[]) {
std::cout << argv[1];
}
When I run the executable, it gives me the following. So the newline
character is not passed to the program. Is it possible to pass the
newline character to a program?
$ ./main.exe "\n"
\n
> On Nov 19, 2:54 pm, Lew Pitcher <lpitc...@teksavvy.com> wrote:
>> On November 19, 2009 15:33, in comp.unix.shell, PengYu...@gmail.com
>>
>> (pengyu...@gmail.com) wrote:
>> > I'm wondering how to pass a newline character as an argument to a
>> > command in bash.
[snip]
> When I run the executable, it gives me the following. So the newline
> character is not passed to the program. Is it possible to pass the
> newline character to a program?
>
> $ ./main.exe "\n"
> \n
Seebs gave you the answer to that one...
./main.exe "
"
embed a newline directly into your command (placed between quotes, so that
the shell interpreter knows that it is part of the commandline, rather than
the end-of-command marker)
Take your pick:
NL='
'
NL=$'\n'
printf -v NL "\n"
etc....
--
Chris F.A. Johnson, author <http://shell.cfajohnson,com/>
===================================================================
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
===== My code in this post, if any, assumes the POSIX locale =====
===== and is released under the GNU General Public Licence =====