Creating Printing Program in bash

HI

I am trying to create a bash script to print whatever i type in

It has to have these below to define the size of the label and what size to print the text

N
q609
A100,10,0,5,2,2,N," "
P1

It has to be sent to below

> /dev/usblp0

So what it has to be is

Written Text ----> sent to printer

and i want to be able to write what i want to print

PLEASE HELP!!!!!!!:frowning:

Any printer which understands postscript or PCL can also understand raw text so perhaps, at its very simplest, you could do:

sed 's/$/\r/n' >/dev/usblp0

When run in a terminal, sed will read from the keyboard, convert \n into \r\n, and print it back out into /dev/usblp0.

When you're finished typing, hit control-D to tell sed the document is finished and to quit. You may not see any printing happen until you do, unless you have an old-fashioned tractor feed printer. Even for those, you won't see any printing until you finish a line with enter...

What I dont get is what do you mean by written text sent to printer...
The rest:
You put the desired sequence in a file, you send it to the printer ... then ? see above...
I would use an alias for setting the printer, like that you could have a few settings you would call before to print...

i dont want to save a file and then use that code every time i just want to be able to type then print because i have like a thousand codes to print

Why not type the thousands of things into one big file, then? :confused: Then just print the big file.

I suspect if you explained exactly what you're doing better, we could find better ways to do it.

Sorry im not that good at explaning my self
I have a lp 2844 label printer and i have to print stickers out with a code on each of them for items that are going to be stored so i can keep track of them in an excel file

You want to generate numbered stickers?

How do you usually use this printer? It may be proprietary app-specific, and may be easier to use it than try and write a whole printing system from scratch.

This printer apparently speaks EPL2

correct but i want to save a bash file so i can use it again and again

---------- Post updated at 01:39 PM ---------- Previous update was at 01:34 PM ----------

This is the epl2 code for the demensions
N q609 A100,10,0,5,2,2,N," " P1

You said in post #4 that you didnt want a file so you can use again and again...

From their EPL2 examples, perhaps something like

for ((N=1; N<3; N++))
do
        CODE=`printf %08d $N`
        cat <<EOF
N
B1,5,0,3,3,7,40,B,"$CODE"
P1
EOF
done | sed 's/$/\r/' > /dev/usblp0
1 Like

I think he means he wants a bash script which generates lots of similar labels, instead of a text file containing EPL2 commands which he edits by hand.

That's only the text to clear the buffer. What code would you actually use to print a label? And how do you usually send these codes to the printer?

1 Like

This is what i got so far you sent me on the right track but
IS it possible to put two lines in a variable

#!/bin/bash
newlabel="N"
labelwidth="q609"
labeltext='A100,10,0,5,2,2,N,"PC109":)\n TExt:)'
endlabel="P1"

echo $labeltext

---------- Post updated at 02:01 PM ---------- Previous update was at 01:59 PM ----------

sorry if i sound stupid im really new to bash

---------- Post updated at 02:02 PM ---------- Previous update was at 02:01 PM ----------

i started today

In the future, please place source code and program output inside code tags when posting. It will prevent the problems you are having, like smilies appearing in the middle of your code.

[ code ] #!/bin/bash ... [ /code ] without the spaces in the tags and it will appear as

#!/bin/bash ...

It's even easier than you think to put two lines into a variable. Don't put in \n -- put in a real newline.

VARIABLE="line1
line2
line3"

Also, be sure to quote the variable when you use it, to prevent the shell from processing any of the whitespace.

echo $variable # This may convert newlines into spaces
echo "$variable" # this will not process the text inside, printing it raw
1 Like