Doubt regarding stderr


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Doubt regarding stderr
# 1  
Old 06-10-2018
Doubt regarding stderr

Hi All,
I am writing a shell script code. and i want the stderr to be send to a file and the stdout to be displayed in terminal. In my shell script code i use a read command to get data from user.
Code:
read -r -p "Enter the type :" data

and while i execute my script i use
Code:
./my_script.sh 2> filename

My doubt is why Enter the type: which I use with read command is not displayed in terminal, but in STDERR instead (filename) ??

Any insight will be helpful to meSmilie

Last edited by rbatte1; 06-11-2018 at 10:55 AM..
# 2  
Old 06-10-2018
Welcome to the forum.


That's a feature of your shell, e.g. man bash:
Quote:
-p prompt
Display prompt on standard error, without a trailing newline, before attempting to read any input. The prompt is displayed only if input is coming from a terminal.
# 3  
Old 06-10-2018
Thanks @RudiC for your answers,

But even if i remove -p option from read command, same output as previous is observed.

Last edited by rbatte1; 06-11-2018 at 10:55 AM..
# 4  
Old 06-10-2018
Which is difficult to believe.


Please
- tell your OS and shell versions
- show your command
- post the contents of filename
# 5  
Old 06-11-2018
i got it now....Thanks

Last edited by Vinoth R; 06-11-2018 at 01:36 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

can't get stderr port

Hi Experts, i have a solaris 9 OS and i get the following message repeated many time in my /var/adm/messages : Oct 31 16:30:44 baobab rsh: can't get stderr port: Cannot assign requested address have you any idea how can i resolve this issue ??:confused: thanks for help (2 Replies)
Discussion started by: lid-j-one
2 Replies

2. Shell Programming and Scripting

How to redirect stderr to a file as well

Hello everyone, I'm a nooby in Linux, and I need some help. I have a shell script like this: echo "Start of script" > ../My_Log_Dir/Script_Name.log .. cp ../My_DataIn/File.txt ../My_DataOut/ 2>> ../My_Log_Dir/Script_Name.log rc=$? .. echo "End of Script" >>... (5 Replies)
Discussion started by: H.Faria
5 Replies

3. UNIX for Dummies Questions & Answers

how to get stderr

Hello I try to store stderr into a variable, then if this var is not empty i send an email and stop my script. I think my problem is due of "<$dump" into my command line. my bad command line (see samples below on this post) if ! $returnedStr ; then echo ERROR READING DUMP: ... (8 Replies)
Discussion started by: giova
8 Replies

4. Shell Programming and Scripting

stderr/stdout

Can somebody explain to me why the diff output is not going to stderr? Yet when I issue a diff from the command line the return code is -ne 1. I am guessing diff always writes to stdout??? Is there away I can force the difff to write to stderr USING THE CURRENT template. If possible, I... (5 Replies)
Discussion started by: BeefStu
5 Replies

5. Shell Programming and Scripting

Append stderr

Hi everybody. I was used to redirect stderr to a file in this way, calling a generic script:./myScript &> output.logBut now I need something more sophisticated...Inside a bash script I launch an executable in this way:${command} >> "${globalLogFile}"So I redirect the stdout into globalLogFile.... (14 Replies)
Discussion started by: canduc17
14 Replies

6. Shell Programming and Scripting

How to use tee with stdout and stderr?

I have been doing this: make xyz &> xyz.log &; tail -f xyz.log The problem with this is that you never can ge sure when "make xyz" is done. How can I pipe both stderr and stdout into tee so both stderr and stdout are copied both to the display and to the log file? Thanks, Siegfried (3 Replies)
Discussion started by: siegfried
3 Replies

7. Shell Programming and Scripting

STDERR output

Hi, Need some help here on a script I'm writing. I know that STDERR is normally done is this manner: script 2>stderr.out However, if I wanted to output the stderr from a rsh command how do I do that? Example: su - username -c "rsh $hostname /opt/gilberteu/scriptname" 1>stdout... (5 Replies)
Discussion started by: gilberteu
5 Replies

8. Shell Programming and Scripting

precedence of stderr and stdout

#!/usr/bin/perl open(STDOUT, ">>$Textfile") open(STDERR, ">>$Textfile") print "program running\n"; $final = join("+", $initial,$final) #5 close (STDOUT); close (STDERR);Hi all, above is my perl code. Notice i have captured the stdout and stderr to the same textfile. my code is expected to... (1 Reply)
Discussion started by: new2ss
1 Replies

9. UNIX for Dummies Questions & Answers

stderr redirection

Does anyone know away of redirecting the stderr for a bourne or korn shell script to a file. (5 Replies)
Discussion started by: blakmk
5 Replies

10. Programming

stderr

in fprint(stderr, "lkjalsdi\n"); what does stderr mean? thanks (1 Reply)
Discussion started by: dell9
1 Replies
Login or Register to Ask a Question