You haven't said which OS, etc., you are on, so you might have to adapt the following a bit:
In principle every device in Unix/Linux has a "device file", which resides in /dev. In the case of a terminal this is most probably /dev/ttyX, where "X" is some number and the device file is a character device. For instance, from my Ubuntu system:
Reading from such a device will give you whatever a user sitting at this terminal types, writing to such a device will produce the output at that screen. So, after making sure you are allowed to write to and read from the terminals device file you could probably direct your <stderr> output to it by
Thanks for your reply. The main issue I am having is reading in output from a terminal to a variable in the bash script. I know the following won't work but hopefully it can illustrate what I am trying to achieve.
First off, I'd like to warn you: using backticks is a very, very, bad idea: they are outdated, they have a lot of drawbacks, they are only supported for backwards compatibility purposes (with some scripts from the seventies) and you should forget that they exist. Instead of
use
which does the same, only much better.
Quote:
Originally Posted by colinireland
reading in output from a terminal to a variable in the bash script.
terminals don't have output - only processes have output. If you start a process you can redirect its output to <stdout> and/or <stderr> (to your terminal, a file or the device another file descriptor points to). There is no way to redirect the output of a process you don't have started.
If you want to start an xterm and display the output of some process there, you have to:
1. create the terminal window
2. find out the device file attached to it
3. start your process and redirect its output to the device file in question.
In bash, you can do something like this:
#!/bin/bash
echo -n "What is your name? " > /dev/tty
read thename < /dev/tty
How can I do the same in python?
I have a python script that has the following content:
#!/usr/bin/python2.7
import getpass
import sys
import telnetlib
import... (2 Replies)
Hi,
I am working on a script, which requests users to enter input.
Ex: read -p "Please enter your email id:" email
I don't want users skipping this entry, this has to be mandatory.I dont want to proceed without input.
I can do a check if variable $email is empty and proceed if not.But, i... (7 Replies)
Hi,
I'm using read in a script to prompt and receive input.
read -r -p "Do you also want to deploy folder? " response
This works fine, however, if I remotely execute the same script via ssh, at this point in the code, I don't see the message at all, but it waits for input. I could echo... (1 Reply)
Dear Friends,
I am looking for a shell script to merge input files into one file .. here is my idea:
1st paramter would be outfile file (all input files content)
read all input files and merge them to input param 1
ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
I'm a beginner to the Linux programming and trying my hands on some device driver examples while practising. The below code (a trimmed down version of tiny_tty.c from ldd3 book) loads perfectly using insmod and I'm able to see it in /proc/tty/drivers , /proc/modules and device nodes are getting... (1 Reply)
My script needs to get some input from the user and go as a background process and run.
I have something like
read input.
do
while ...
if
..
fi
done
can i use nohup inside the script?? (7 Replies)
Hi
I am new to writing script and want to use a Bash Piped while-read and read from user input.
if something happens on server.log then do while loop or if something happend on user input then do while loop.
Pseudocode something like:
tail -n 3 -f server.log | while read serverline || read... (8 Replies)
I have a script.
#! /bin/bash
echo "Enter a word: "
read word
echo $word
That outputs like this..
Enter a word:
hello
hello
But how can i read on the same line the question is printed?
Like this..
Enter a word: hello
hello (2 Replies)
Hi,
I need to provide more than one character to "> /dev/tty" through terminal/keyboard input, I have this:
ok=false
while
do
echo " Enter r1 to reformat "
> /dev/tty
read choice
case $choice in
)
echo " bla bla bla "
;;
done
However, in this way,... (3 Replies)
More details: Unicode, Framebuffer. I tried to press Esc and then what should follow, letters or brackets, but seems not to work. Probably i do something wrong. If somebody is familiar with escape sequences in the console, how do you do that?
Thanks in advance. (4 Replies)