Skip to content

Line Discipline in Unix/Linux Machines

Posted on 06 July, 2020

Line discipline handles things like backspace and also generates various signals for special characters like Ctrl + C/Z etc.

stty -a will display all these settings. To know more do man ssty.

Demo

Other than Ctrl+c and Ctrl+z which you already know about. Here are some other tricks.

Fire up your terminal. And start typing....

Keyboard ShortcutDescription
Ctrl+?Delete the last input character, Basically Backspace (See what I am talking about, ^? can be used in terminals which may not support the backspace key
Ctrl+qErase line, works like carriage return /r
Ctrl+aMoves cursor to beginning of line
Ctrl+eMoves cursor to end of line
Ctrl+wDelete the last input "word"
Ctrl+kErase line to the end, from current cursor position
Ctrl+yPaste the last erased text

Apart from these line input specific keyboard shortcuts. We also have ...

Multiline Input

Use / for continuing the multiline input.

bash
bhupesh@dev: hello my name\
is\
bhupesh\
check\
> my boi\
> hoooo\
>

A better version

bash
#!/bin/bash

echo -e "Enter Commit Message (Ctrl+d to stop) : "
commit_message=$(</dev/stdin)

echo -e "\n\n$commit_message"

Make it executable and run.

bash
Enter Commit Message (Ctrl+d to stop) : 
- fixed bug #454
- Increase reponse time
- style fixes


- fixed bug #454
- Increase reponse time
- style fixes

All of this is controlled by the tty driver

Resources

Written while 🙇🏽‍♀️