stty in .profile causes: "stty: 'standard input': Inappropriat ioctl for device
I added into my .profile file the command stty werase ^H (The command makes it possible that i can delete a word with Ctrl + Return).
But whenever i start my PC it prints the following error:
Error found when loading /home/stefan/.profile:
stty: 'standard input': Inappropriate ioctl for device
As a result the session will not be configured correctly. You should fix the problem as soon as feasible.
I tried to find the error with strace -f -o <path-to-error> stty werase ^H.
I have no idea tho what it does cause. Link for those who want to read it (pastebin).
1 Answer
stty acts on a device which is its stdin:
Although no input is read from standard input, standard input shall be used to get the current terminal I/O characteristics and to set new terminal I/O characteristics.
The error you got means stdin is not a terminal. Using a terminal you can still reproduce the error by redirecting stdin:
</dev/null stty werase ^H.profile is meant to be executed as one-time setup (e.g. by a login shell). In your case the file is apparently parsed by something not connected to a terminal. But even if stty in .profile succeeded, it wouldn't affect all possible terminals you could use later.
You need to run stty in each interactive shell separately. For Bash a good place is .bashrc (other shells use other files). It's a fairly common practice that .profile detects Bash and sources .bashrc. In some (rare, rather pathological) cases .bashrc may be sourced in a non-interactive shell, so you may want to test if the shell is interactive just in case:
# in .bashrc
[[ $- == *i* ]] && stty werase ^HOr better explicitly check if stdin is a terminal:
# portable approach
[ -t 0 ] && stty werase ^HOr just silently ignore an error (if any) from stty:
# portable approach
stty werase ^H 2>/dev/nullWhatever you choose, the main point is .profile is not a good place for this.