Other Options after #! (Shebang)

hruodr

Well-Known Member

Reaction score: 47
Messages: 380

I want a script semacs that open emacs with what was sent to /dev/stdin in
the buffer. Example:

echo abc | semacs

Should open emacs with "abc" in the buffer. The idea is to exploit emacs' EasyPG assistant in many "primitive" mail readers through piping.

The following does not work:

Code:
#!/usr/opt/bin/emacs --insert /dev/stdin
But the following does work:

Code:
#!/bin/sh
exec /usr/opt/bin/emacs --insert /dev/stdin
and

Code:
#!/bin/sh
/usr/opt/bin/emacs --insert /dev/stdin
My question: why the first does not work? Does someone have a better idea?
 

Zirias

Aspiring Daemon

Reaction score: 224
Messages: 609

I'm not entirely sure I understand the question ... are you expecting your system to somehow execute a plain text file?

Or did you just forget the #! on your first example ... in this case, the answer is probably quite simple: A script is fed to its interpreter (specified in the shebang line) as a command line argument, and this probably isn't a valid invocation of emacs any more (looking like /usr/opt/bin/emacs --insert /dev/stdin semacs)

Just use your second form, it has the little overhead of invoking /bin/sh, but the exec makes sure the process is replaced with emacs.
 
OP
OP
H

hruodr

Well-Known Member

Reaction score: 47
Messages: 380

I forgot the #! in the forum-article (corrected). The script with the line

Code:
#!/usr/opt/bin/emacs --insert /dev/stdin
Does not work. It does execute emacs, but it does not insert "abc". I get in emacs' minibufer:

Code:
Unknown option `--insert /dev/stdin'
Perhaps it considers all what follows the first space as an (one) argument, even it there are more spaces.

The other scripts works only with X11. In the console I get:

Code:
emacs: standard input is not a tty
Is ttyv1 really not a tty?!
 

unitrunker

Active Member

Reaction score: 88
Messages: 234

Seems like it would be easier to write the text to a file and open emacs on that file.
 
Top