SIGINT to cancel read in bash script?

后端 未结 2 1192
無奈伤痛
無奈伤痛 2021-01-12 21:48

I\'m writting a bash wrapper to learn some scripting concepts. The idea is to write a script in bash and set it as a user\'s shell at login.

I made a while loop that

2条回答
  •  醉梦人生
    2021-01-12 22:19

    You could use a tool like xdotool to send Ctrl-A (begin-of-line) Ctrl-K (delete-to-end-of-line) Return (to cleanup the line)

    #!/bin/bash
    trap "xdotool key Ctrl+A Ctrl+k Return" SIGINT;
    unset command
    while [ "$command" != "quit" ] ;do
        eval $command
        read -e -p "$USER - SHIELD: `pwd`> " command
      done
    trap SIGINT
    

    But I strongly invite you to rtfm... In searching for ``debug'' keyword...

    man -Pless\ +/debug bash
    

提交回复
热议问题