naru
naru

Reputation: 106

How to show output when using /bin/zsh -c print?

I'm confusing when I use /bin/zsh -c with print command, there is no output.

How can I get foo in next prompt with /bin/zsh -c?

$ print -z foo
$ foo
(↑this is expected result that foo is in next prompt)

$ /bin/zsh -c print -z foo

$
(not show foo in next prompt)

Upvotes: 0

Views: 466

Answers (2)

blami
blami

Reputation: 7421

This happens because -z option prints into editing buffer (for the next prompt). So if you run:

$ /bin/zsh -c 'print -z FOO'

it will push FOO in the next prompt editing buffer of that /bin/zsh -c sub-shell. But that sub-shell will exit immediately after running print -z FOO and so FOO will end up discarded in void. There's no way that subshell can manipulate its parent shell editing buffer (they are completely different processes with their own editing buffers).

If you just want to inject FOO to the next command line of current shell just run:

$ builtin print -z FOO

and the next prompt will look like this (_ being cursor waiting for user input):

$ FOO_

Upvotes: 1

Jens
Jens

Reputation: 72707

Run it in the current shell, instead of in a child.

$ print -z echo hello
$ echo hello             <-- Already in the buffer, only pressing ENTER now 
hello
$

Upvotes: 0

Related Questions