How would you represent EOF in bash?

前端 未结 5 1077
执念已碎
执念已碎 2020-12-24 07:31

I\'m trying to do something like

read -d EOF stdin

for word in $stdin; do stuff; done

where I want to replace \'EOF\' for an actual repre

5条回答
  •  天命终不由人
    2020-12-24 08:26

    litb & Daniel are right, I will just answer your "Just for kick" question: Bash (as any command line unix program in general) only see characters as bytes. So you cannot match Alt-v, you will match whatever bytes are sent to you from the UI (pseudo-tty) that interpret these keypresses from the users. It can even be unix signals, not even bytes. It will depend on the terminal program used, the user settings and all kind of things so I would advise you not try to match them.

    But if you know that your terminal sends C-v as the byte number 22 (0x16), you can use things like:

    if test "$char" = '^V'; then...
    

    by entering a real ^V char under your editor (C-q C-v under emacs, C-v C-v under an xterm , ...), not the two chars ^ and V

提交回复
热议问题