LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-18-2009, 02:35 AM   #1
crispyleif
Member
 
Registered: Mar 2005
Location: Norway, by the coast
Distribution: Debian and the likes
Posts: 190

Rep: Reputation: 31
Bash for beginners @ TLDP.ORG, chapter 8, question


According to the guide:

ls -l * 2> /var/tmp/unaccessible-in-spool
will redirect standard output of the ls command to the file unaccessible-in-spool in /var/tmp.

I can't get that to be correct, if I issue such a command I get an empty file and standard output on the screen. Ideas ?
 
Old 02-18-2009, 02:52 AM   #2
ebmi
LQ Newbie
 
Registered: Oct 2006
Posts: 18

Rep: Reputation: 0
`command 2> file` means that stderr will be redirected to "file"

`command 1> file` is for redirecting stdout to "file"

Cheers.
 
Old 02-18-2009, 03:14 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Yes. There is no message sent to the standard error. When you use redirection to a file, the file is created when the command execution starts, so that it can rest unused if no error message comes out from the execution. If you want to redirect the standard output together with the standard error you can do this:
Code:
ls -l * > /var/tmp/unaccessible-in-spool 2>&1
that is you redirect the standard output to the file, then the standard error to the same place as the standard output. The order of redirections is important!

You can also try a different command to see the standard error file populated by an error message:
Code:
ls -l pippo 2> /var/tmp/unaccessible-in-spool
provided you do not have a file named "pippo" in your current directory.
 
Old 02-18-2009, 03:25 AM   #4
ebmi
LQ Newbie
 
Registered: Oct 2006
Posts: 18

Rep: Reputation: 0
Bash also supports

`command &> file`

for redirecting both stdout and stderr into "file". Other shells (such as dash) may or may not support this.
 
Old 02-18-2009, 03:58 AM   #5
crispyleif
Member
 
Registered: Mar 2005
Location: Norway, by the coast
Distribution: Debian and the likes
Posts: 190

Original Poster
Rep: Reputation: 31
Thanks for all help.

I actually agree 100% with my result and with you.

when a command that produces no errer redirects that non-existent
errer to a file, I expect it to be empty.

What confused me was that the guide said that "2>" would redirect stdout,
which it doesn't.
 
Old 02-18-2009, 05:17 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Must be a typo in the guide. It happens... sometimes you can't trust the book...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
looking for a bash for absolute beginners guide dasy2k1 Linux - Newbie 8 11-11-2016 12:50 PM
Where is the Embedded Linux "HOWTO" at http://www.tldp.org ? t3gah General 14 06-06-2005 06:35 AM
tldp.org and linuxdocs.org emailssent General 2 09-20-2004 06:59 AM
can someone suggest a site for internet sharing in RH8? docs from TLDP.org didnt work kublador Linux - Networking 2 03-28-2003 11:00 AM
chapter 5 - bash won't build shaurz Linux From Scratch 3 02-05-2003 04:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration