0

I have the following alias that is sourced during login on my Mac PowerBook running El Capitan, OS X 10.11.3 with Developer Tools install and command line utilities installed:

alias prt_2up="enscript -G -p - \$@ | quarto -2 | lpr -P $PRINTER"

Note that $PRINTER is defined in .bashrc as:

export PRINTER=EPSON_Stylus_CX4800___barsoom

I "used" to use this as:

prt_2up file.txt

and it created a printout with 2 pages per print page with no problems.

Now, I get the following error:

19:54:50 1z [woo:~] > source .bashrc
19:54:54 1z [woo:~] > echo $PRINTER
EPSON_Stylus_CX4800___barsoom
19:54:59 1z [woo:~] > prt_2up test.php
enscript: couldn't open input file "noclobber": No such file or directory
no output generated
lpr: The printer or class does not exist.

Don't understand why $PRINTER isn't said to exist and what the input file "no clobber" is about. BTW, I've done set +o no clobber also. It doesn't appear to matter whether I set it on or off. The quarto is another utility that allows putting more than one page to a sheet of paper. Where does the noclobber come from?

I've also tried using $@ without the leading \ also. No joy.

Suggestions appreciated.

1 Answer 1

1

I can't tell you why it worked before, but I definitely see a problem. Before I go into detail, let me suggest you try this:

prt_2up () { enscript -G -p - "$@" | quarto -2 | lpr -P "$PRINTER"; }

The problem I see is with the use of $@ in an alias as opposed to a shell function. Look at the following:

$ set -xv
$ alias foo="echo \$@"
alias foo="echo \$@"
+ alias 'foo=echo $@'
$ foo a b
foo a b
+ echo a b
a b
$ alias bar="echo \$@ | cat"
alias bar="echo \$@ | cat"
+ alias 'bar=echo $@ | cat'
$ bar a b
bar a b
+ echo
+ cat a b
cat: a: No such file or directory
cat: b: No such file or directory
$ baz () { echo "$@" | cat; }
baz () { echo "$@" | cat; }
$ baz a b
baz a b
+ baz a b
+ echo a b
+ cat
a b

The bar alias doesn't do the same thing as the baz shell function, and neither does foo.

$ set 1 2 3
set 1 2 3
+ set 1 2 3
$ echo "$@"
echo "$@"
+ echo 1 2 3
1 2 3
$ alias foo
alias foo
+ alias foo
alias foo='echo $@'
$ foo a b
foo a b
+ echo 1 2 3 a b
1 2 3 a b

The $@ in the alias refers to arguments to the shell itself, while $@ in a shell function refers to arguments to that function.

Sign up to request clarification or add additional context in comments.

2 Comments

Using your suggestion, I created a separate file in my execute path: It has: 16:47:43 1z [woo:~] > less bin/prt_2up #!/bin/bash # # Print file two pages to the sheet # prt_2up() { enscript -G -p - "$@" | quarto -2 | lpr -P "$PRINTER"; } When I execute it I get: enscript: couldn't open input file "noclobber": No such file or directory no output generated lpr: The printer or class does not exist.
Ignore above. I still had the alias active. After restarting a terminal session where I had removed the alias and used the function, I got no errors and it appears to work. Thanks,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.