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

邮差的信 提交于 2020-08-10 20:09:34

问题


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


回答1:


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

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

$tty contains the actual tty device name.



来源:https://stackoverflow.com/questions/63313302/how-do-i-fix-bash-error-dev-tty-no-such-device-or-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!