I've seen this done and I used to be able to do it. I had it documented in a file that was clobbered recently in a backup issue.
I have a text string I want to print from bash using lpr. I know I can print text files easily, but how can I print text that is just in quotation marks or in a string without first saving it as a file, then printing the file?
lpr submits files for printing. Files named on the command line are sent to the named printer (or the system default destination if no destination is specified). If no files are listed on the command-line, lpr reads the print file from the standard input.
To print a file with a specific printer, execute the lp command with the '-d' option or lpr command with the '-P' option. Consider the following commands: lp -d <printer name> <file name>
To print a document on the default printer, just use the lp command followed by the name of the file you want to print.
The LPR command is used to print a file directly without using a Windows application that supports printing. Attention: The LPR command has a limit of 2 GB for sending print jobs.
You could use here-strings with bash
lpr <<< "text string"
or if your string is contained in a variable
lpr <<< "$var"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With