Search code examples
linuxbashcurlgoogle-colaboratorytty

How do i fix bash error - /dev/tty No such device or address


As the question specifics ,i am getting this error while executing my bash script

In exact terms i get following error

bash: line 26: /dev/tty: No such device or address
bash: line 29: /dev/tty: No such device or address

Here are the concerned Line 26 and 29 in script respectively which causes the issue

read -e -p "Paste the links : " links </dev/tty
read -e -p "Enter your input : " sub </dev/tty

If someone wonders, i cannot simply remove writing to </dev/tty from line 26 and 29 , it causes different issues .. So basically i need fix or get alternative for writing to /dev/tty

I am executing my script by running - curl raw_link | bash

Preferably i want a solution which only requires me to my edit my existing script .i don't want to run the script after saving it locally or execute it using any other way apart from curl raw_link | bash

ls -l /dev/tty returns the following

crw-rw-rw- 1 root root 5, 0 Aug  8 09:28 /dev/tty

ls -l </dev/tty returns the following

/bin/bash: /dev/tty: No such device or address

Also i would like to mention that this issue doesn't seem to be happening on every machine , i intend to use this script on Google Colab where i definitely do get this issue


Solution

  • To fix the bash error, you can try this workaround :

    tty=$(readlink /proc/$$/fd/2)
    read ... < $tty
    

    $tty contains the actual tty device name.