回显文本作为 bash 中的建议提示

Var*_*Agw 6 bash line-editor

是否可以更改出现在$PS1. 这是用户输入的内容。我想建议以后my_function运行一些命令。当然我应该能够使用退格键修改/删除它

root@linux: 
root@linux: ls
aplha beta gamma
root@linux: my_function
root@linux: echo_something_here (It should be deletable by me)
Run Code Online (Sandbox Code Playgroud)

ago*_*old 3

根据这个答案,您可以使用expect(您可能必须先安装它):

#!/usr/bin/expect -f

# Get a Bash shell
spawn -noecho bash

# Wait for a prompt (in my case was '$', but your example only put ':')
expect ": "

# store the first argument in a variable
set arg1 [lindex $argv 0]

# Type something
send $arg1

# Hand over control to the user
interact

exit
Run Code Online (Sandbox Code Playgroud)

现在您可以调用它(假设您将其另存为my_function):

root@linux: ./my_function "some text here"
root@linux: some text here
Run Code Online (Sandbox Code Playgroud)

唯一的不良影响可能是它开始了新的狂欢。