This discussion assumes that you are using a shell that uses basic Bourne shell redirection syntax (such as bash, ksh, or sh). The csh shell and its derivatives handle redirection differently.
The shell redirection operator 2>&1 tells the shell to redirect all ouput written to file descriptor 2 (the standard error output stream) to the file to which file descriptor 1 (the standard output stream) is directed. The order of the redirections is important. Try the following examples to see the difference.
EXAMPLE 1:
This command will send the standard output from echo to your terminal and the standard error output to your terminal (unless you have performed redirections for one of these output streams that were not associated with another command).
If this isn't what happens, log out and log back in and try again to get a fresh shell execution environment with standard output and standard error output directed to your terminal.
EXAMPLE 2:
This command will send the output from echo to the file named fd1 and the diagnostic message from cp to the file named fd2. You can verify this by running the commands:
and
EXAMPLE 3:
This command will send the output from echo to the file named fd1 and the diagnostic message from cp to the file to which file descriptor 1 is directed (which in this case is the file named fd1). Again, you can verify this by running the command:
EXAMPLE 4:
This will send the diagnostic output from the cp command to the file to which file descriptor 1 is directed (your terminal) and the output from echo to the file named fd1.
If the commands:
send any output to logfileA.txt something is seriously wrong. This all works as I have described when tested on Mac OS X Version 10.7.5 with both bash and ksh. When I tried these using csh on OS X, it gives the diagnostic: Of course there is one other possibility: Do program1a, program1b, and program1c internally redirect their output to logfileA.txt? If so, we have wasted a lot of time, and I assume you know how to fix your problem.
Don Cragun, thanks very much for the explanation. It was very clear and useful. It worked!
Is this possible? I am attempting to display a new xterm window and tail -f the log file within that new window. I am currently working on a solaris 8 machine if that has any different meaning than the other platforms. As you can see, I am a newbie to this forum and to UNIX. Any help would be... (2 Replies)
Hello All,
I am newbie to unix.I am trying to use NOHUP command in shell script it works fine with only "nohup test.sh 10 &" and "/opt/user/nohup test.sh 10 &" gives an error saying "ksh: /opt/user/nohup : not found".
Can anybody please guide me to make it work.
Thanks
Blazix (9 Replies)
Hi!
Letīs say I want copy dump-files to a location.
These dump-files vary between 80 and 280MB and will be produced in about 1min or less.
I have a cronjob which (not only) copies those.
So how can I find out whether a file is currently produced or not?
Because if my script works with these... (2 Replies)
Is it possible that I get all the syslog messages from /var/log/messages redirected to some FIFO as and when any new messages comes.
In exact, I need to duplicate the messages to a FIFO, the moment a new message is logged; from where another process reads and does some processing without... (12 Replies)
# whoami 2>/dev/null
whoami: not found
#
Why the error message not getting redirected to /dev/null ...
The shell is
# echo $SHELL
/sbin/sh
For other commands it is working
# ls aaa 2>/dev/null
#
Is there any other way to redirect the err msg from whoami Thank you for your... (7 Replies)
I'm trying to run a compress script in the background, but I even though the script is running in the background I get "Sending nohup output to nohup.out." and the screen just stays there. How can I make the script run in background and make my command prompt come back.
I was using:
nohup... (2 Replies)
Suppose executable X produces files A and B from nothing, Y produces C from A, Z produces D from B, and my final goal is to produce C and D. I wrote the following makefile:
.PHONY: all
all: C D
C: A
Y A
D: B
Z B
A B:
X
This makefile seems to reflect all dependencies, as it should... (2 Replies)
Hi,
Pls check that '|' and '+' present in Step-1 are not copied to log file in Step-3.
Pls suggest how to get the exact output from Step-1 (i.e. with out losing '|' and '+') in to a log file
~Thanks
Step-1: Execute command
> mysql -utest -ptest -htesthost testdb -e "select * from... (3 Replies)
Hi All,
Please could anyone advise what the purpose of the dot syntax in the following command means:
tar -cvf ${WORKING_BACKUP_ROOT}/${TAR_ARCHIVE_FILE} . >/${BACKUP_ROOT}/${ARCHIVE_LOG}
Many thanks (2 Replies)