228k views
4 votes
How to supress the "stty: 'standard input': Inappropriate ioctl for device" error

User Zakiya
by
6.7k points

1 Answer

6 votes

Final answer:

To suppress the 'stty: 'standard input': Inappropriate ioctl for device' error, redirect stty commands to /dev/null or check if the script is being run interactively. The error commonly occurs in non-interactive environments.

Step-by-step explanation:

The 'stty: 'standard input': Inappropriate ioctl for device' error usually occurs when a script that is meant to be run in an interactive shell is run in a non-interactive environment, such as a cron job or a script executed by an automated process. To suppress this error, you can redirect the stty commands to /dev/null, or you can check if the script is being run interactively by checking if /dev/tty exists or by using the [-t 1] conditional expression to test if the stdout is a terminal.

For example, to suppress the error, you can modify the stty commands like so:

stty <some stty command> 2>/dev/null

Or, in a script, you can test if the output is a terminal before executing stty:

if [ -t 1 ]; then
stty <some stty command>
fi

Note that the adjustments you make will depend on the specific context and commands in your script.

To suppress the 'stty: 'standard input': Inappropriate ioctl for device' error, you can redirect the standard input for the 'stty' command from the keyboard to a file. This can be achieved by using the '<' symbol followed by the file name.

For example, if you want to suppress the error while running the command 'stty -echo', you can use the command 'stty -echo < input.txt', where 'input.txt' is an empty file. This way, the 'stty' command will consider the file as the input instead of the keyboard and the error will be suppressed.

User Chandana Kumara
by
7.1k points