Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 of echo?

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 over print 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
share|improve this question
    
What OS are you on? –  slm Nov 9 '13 at 4:09
    
@slm I'm on ubuntu –  Prayag Upd Nov 9 '13 at 4:12
    
OK, see my answer and let me know if it helps –  slm Nov 9 '13 at 4:13

2 Answers 2

up vote 8 down vote accepted

You're confusing many things here, let me try and tease this apart for you.

  1. 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 which print is one of them.

  2. print --"text/plain" "prayag works on JVM" and other forms

    The 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.

  3. 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 the echo you're using, but serves a similar purpose.

  4. print in shells such as zsh/ksh

    Thanks to @Gilles comment, the print command you're looking for is most likely the one that is built into shells such as zsh and/or ksh. 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 or ksh.

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

share|improve this answer
1  
Sometimes I think you never sleep :-). +1, couldn't have answered this better –  1_CR Nov 9 '13 at 4:10
2  
@PrayagUpd - thank you for your Q. Believe it or not I learn something with each Q too so I appreciate them immensely since they drive me to learn things in a much more detailed fashion. 8-) –  slm Nov 9 '13 at 4:24
1  
@PrayagUpd - yeah I looked up your IP. I use road runner here in the US. I self host my blog so they're likely blocking based on geographical region IP? I'd been meaning to move my blog to something that is more accessible. –  slm Nov 9 '13 at 5:19
2  
@PrayagUpd - you're welcome, thanks for letting me know about my blog. Obviously I want it to be as accessible as possible, no point in writing things up if ppl can't seem it. –  slm Nov 9 '13 at 5:40
1  
print is also a ksh (and zsh) builtin, similar to echo but without the historical quirks. That's probably the ultimate origin of why the asker of that SO question used print. –  Gilles Nov 9 '13 at 14:33

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.