Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a remote (linux) server that I ssh to from my (also linux) pc to print my stuff.

Everything works if I do:

    ssh ${remote_server}
    (now in remote server)
    lpr readme.txt


    ssh ${remote_server} lpr readme.txt -P$PRINTER
    (this works too)

But if I do:

    ssh ${remote_server} lpr readme.txt 
    (I get a "there-is-no-default-printer" error.)

I did set the $PRINTER environment variable such that "ssh echo $PRINTER" gives me the right printer name.

share|improve this question
up vote 3 down vote accepted

Note that running:

ssh <host> echo $PRINTER

...tells you nothing about the remote environment, because $PRINTER will be expanded by your local shell. On the other hand:

ssh <host> 'echo $PRINTER'

...will tell you something useful (note the single quotes).

I suspect that what's happening is that you're setting the PRINTER environment variable in a file that only gets sourced for interactive logins. Are you using bash? Or something else? Where are you setting PRINTER?

share|improve this answer
You are right, ssh <host> 'echo $PRINTER' produces a blank. I set it in both bashrc and bash_profile. Which is the correct place to set it? – alexloh Jun 25 '11 at 14:33

It could be that $PRINTER is set in /etc/profile or ~/.profile, which is ignored for non-interactive sessions.

Your test – ssh echo $PRINTER – is invalid, as the variable is expanded locally, and what gets executed is ssh echo printername.

share|improve this answer

Your Answer


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.