Linux 在bash读取循环中,处理!(感叹号)和补漏白CTRL-Z
我试图用自定义代码扩展bash,这些代码重用bash终止和挂起分叉进程的功能,以及bash对!的扩展 我尝试了代码的一个变体,在其中注释掉了该解决方案中的某些行,并添加了几行用于捕获ctrlz:Linux 在bash读取循环中,处理!(感叹号)和补漏白CTRL-Z,linux,bash,sh,signals,bash-trap,Linux,Bash,Sh,Signals,Bash Trap,我试图用自定义代码扩展bash,这些代码重用bash终止和挂起分叉进程的功能,以及bash对!的扩展 我尝试了代码的一个变体,在其中注释掉了该解决方案中的某些行,并添加了几行用于捕获ctrlz: #!/bin/bash # type "finish" to exit #stty -echoctl # hide ^C # function called by trap other_commands() { #printf "\rSIGINT caught
#!/bin/bash
# type "finish" to exit
#stty -echoctl # hide ^C
# function called by trap
other_commands() {
#printf "\rSIGINT caught "
#tput setaf 1
#printf "\rSIGINT caught "
#tput sgr0
#sleep 1
#printf "\rType a command >>> "
echo ""
}
trap 'other_commands' SIGINT
trap 'other_commands' TSTP
trap 'other_commands' SIGTSTP
#input="$@"
while true; do
printf "\rType a command >>> "
read input
[[ $input == finish ]] && break
bash -c "$input"
done
CTRL C工作得很好,它杀死了创建的进程,但没有杀死bash扩展
然而,CTRLZ是一种工作。
当我执行ls | more然后执行CTRLZ时,它会暂停进程:
dewan 1934441 0.0 0.1 9800 3144 pts/6 S+ 17:00 0:00 bash ctrlc.sh
dewan 1934442 0.0 0.1 9800 3300 pts/6 T+ 17:00 0:00 bash -c ls | more
但在此之后,我无法在bash扩展中执行任何操作:
initx11
j2h
j2h.bat
j2h.jar
j2hlink
jargipc
--More--
^Z
我在这里读到()sigstop不能被捕获,但sigtstp可以被捕获(以防有差异),正如我们看到的,bash允许这样做。我想知道是否有解决办法。取消注释原始解决方案中的行并没有改善情况 第二个问题是我不能使用!在bash扩展中重用历史记录命令。例如不执行最后一个命令
jaroeold pt2t.sed uc
jaroewithoutvt r2b
Type a command >>> !ls
bash: !ls: command not found
Type a command >>>
这个!前缀不是由bash扩展的。有没有办法让bash扩展它?我可以复制功能,但我很好奇是否有人能设计出一个不需要这种复制的解决方案
谢谢,这是我的第一个问题,我想请原谅格式和内容上的错误