print command instead of echo in linux
Solution 1
You're confusing many things here, let me try and tease this apart for you.
-
awk '{print}' ...
This has nothing to do with the
print
you're asking about.awk
is a dynamic programming language which contains its own commands, of whichprint
is one of them. -
print --"text/plain" "prayag works on JVM"
and other formsThe command
print
is for displaying files per the contents of the mailcap file, using the designated "handler" for each particular file type, not for printing strings to the screen.excerpt from the print man page
run-mailcap, view, see, edit, compose, print - execute programs via entries in the mailcap file
run-mailcap (or any of its aliases) will use the given action to process each mime-type/file in turn. Each file is spec‐ ified as its mime-type, its encoding (e.g. compression), and filename together, separated by colons. If the mime-type is omitted, an attempt to determine the type is made by trying to match the file's extension with those in the mime.types files. If the encoding is omitted, it will also be determined from the file's extensions. Currently supported encodings are gzip (.gz), bzip (.bz), bzip2 (.bz2), and compress (.Z). A filename of "-" can be used to mean "standard input", but then a mime-type must be specified.
-
echo
The command
echo
is a builtin command to the shell you're using called Bash (I'm assuming you're using Bash). You can confirm this by using this command:$ type -a echo echo is a shell builtin echo is /bin/echo
You'll notice that
echo
is also a standalone executable,/bin/echo
. This is a different command than theecho
you're using, but serves a similar purpose. -
print
in shells such as zsh/kshThanks to @Gilles comment, the
print
command you're looking for is most likely the one that is built into shells such aszsh
and/orksh
. You can see its usage through the man page,man zshbuiltins
.Example
zsh % print "hello world" hello world
You can run one of these shells by typing
zsh
orksh
.
printf
Perhaps you're looking for the command printf
?
$ printf "%s\n" "hello stringy world"
hello stringy world
$ printf "this is some padded digits: %04d\n" "10"
this is some padded digits: 0010
The command printf
takes a formatting set of special characters so that you can instruct it how you want to display things such as strings or digits etc. See the man page for printf
.
mailcap
So a lot of people are probably oblivious as to the file /etc/mailcap
. This file contains mime-types (headers from files which identifies what type of file a file is). You can then create entries in this mailcap
file which designate what tool to use to open a particular mime-type for a file.
Example
text/html; /usr/bin/sensible-browser '%s'; description=HTML Text; nametemplate=%s.html
application/x-troff-man; /usr/bin/nroff -mandoc -Tutf8; copiousoutput; print=/usr/bin/nroff -mandoc -Tutf8 | print text/plain:-
application/x-ogg; /usr/bin/mplayer '%s'; description="OggVorbis Audio"
application/ogg; /usr/bin/mplayer '%s'; description="OggVorbis Audio"
audio/mpeg; /usr/bin/mplayer '%s'; description="MPEG Audio Format"
audio/x-mpegurl; /usr/bin/mplayer '%s'; description="Icecast Playlists"
audio/x-ms-wax; /usr/bin/mplayer '%s'; description="Audio Format"
The above lines say that if you get a file with the mime-type audio/mpeg
, then use the tool /usr/bin/mplayer
to open this file.
These rules are generally used by the email tool, but other tools can take advantage of these entries within the mailcap
file as well.
If you're interested in learning more about mime-types or mailcap see the following references.
References
Solution 2
You can use printf command to do so,
# printf Hello World
Hello
# printf "Hello World"
Hello World
Well, exatly you need to use print commnad then you can add alias
# alias print='echo'
# print Hello World
Hello World
# unalias print < -- to revert.
also to set permanent,
# export print='echo'
# print Hello Linux
Hello Linux
so,
# export | grep print
declare -x print="echo"
# unset print < -- to revert.
# export | grep print
Related videos on Youtube
prayagupa
(def summary[] (:TCP/IP-socket-programmer "who loves to send and receive bits and bytes") (:using "bytecode instructions which runs on JVM [clojure, groovy, java12]") (and ([sql, nosql])) (also (did [PHP, CLR] socket programming once upon a time)) (does mobile app programming sometimes in [Android] Platform.) (TDD practitioner)) (def resume[] {:stackoverflow_careers "http://careers.stackoverflow.com/prayagupd" ))
Updated on September 18, 2022Comments
-
prayagupa almost 2 years
I simply can print a message in terminal using linux
echo
command.prayag@prayag$ echo "prayag works on JVM" prayag works on JVM
Can I have the same output with
print
command.I actually went through their manuals, where
$ man print
describes it as Run-mailcap-programs which term I never heard before. And came to know that it is used to find the correct program to open a file with, based on MIME.So is there any way to print a simple line using
print
alone instead ofecho
?Found similar kind of problem at Need to assign the contents of a text file to a variable in a bash script, but people suggesting
echo
overprint
there.I tried following, but got issues.
$ print --"text/plain" "prayag works on JVM" Warning: unknown mime-type for "prayag works on JVM" -- using "application/octet-stream" Error: no such file "prayag works on JVM"
It asks for a file, with file provided.
$ print --"text/plain" application.properties Warning: unknown mime-type for "application.properties" -- using "application/octet-stream" Error: no "print" mailcap rules found for type "application/octet-stream"
But got working in combination with
awk
command with a file provided,$ awk '{print}' application.properties prayag works on JVM
-
slm over 10 yearsWhat OS are you on?
-
prayagupa over 10 years@slm I'm on ubuntu
-
slm over 10 yearsOK, see my answer and let me know if it helps
-