我有一个以字符串形式返回命令的函数。如何将此命令作为字符串传递给下一个提示而不执行它。
例如:
函数commandGenerator
将cd ~/some_dir/
作为字符串返回。现在我在终端中执行commandGenerator
:
> commandGenerator
> cd ~/some_dir/
^
Cursor position after execution of commandGenerator.
I can now edit the command or hit enter to execute it.
答案 0 :(得分:2)
内置-z
命令的print
选项将文本写入命令缓冲区。
% print -z "cd ~/some_dir/"
% cd ~/some_dir
您可以在commandGenerator
功能中拨打此电话。当函数退出时,下一个命令行将填充print -z
打印的文本。