Sponsored Content
Top Forums Shell Programming and Scripting Ignoring mv commands "cannot stat" error ? Post 302520612 by mirni on Sunday 8th of May 2011 05:11:54 PM
Old 05-08-2011
Well, the message you're getting is printed on stderr (as opposed to stdout, which is where normal output goes). If you want to just get rid of that stream, this is the easiest way.

Many times it can be useful to ignore all output and just check the return value of command to see whether it exited normally or not:
Code:
grep string someFile &>/dev/null 
case $? in 
  0) echo "found it";;
  1) echo "not found, someFile exists";;
  2) echo "someFile does not exist";;
esac

Redirection &> will redirect both stdout and stderr.

You can specify where does this message go, by manipulating the stderr stream. Stderr is associated by a file descriptor 2 (/dev/fd/2 in bash).

Other than redirecting it to /dev/null, you could redirect it to a file, to capture the stderr, like
Code:
command 2> myErrs.log

or '2>>' to append.

You can also process the stderr by piping it to another command. Reply by alister in this post explains this and might be of interest to you:
https://www.unix.com/shell-programmin...r-process.html

Other than processing what goes OUT of stderr, you might wanna write INTO stderr. Like this:
Code:
$echo "This goes to stderr" >&2

good luck!
mirni

Last edited by mirni; 05-09-2011 at 04:50 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

"read" command ignoring leading spaces

I have to read a file line by line, change it and then update the file. Problem is, when i read the file, "read" command ignores leading spaces. The file is a script which is indented in many places for clarity. How to i make "read" command read leading spaces as well. (3 Replies)
Discussion started by: vickylife
3 Replies

2. UNIX for Dummies Questions & Answers

what is a "find stat() error"

I'm searching for an oracle emtab file. I do a find / -name emtab -print and the first result gives me find: stat() error /apps/tomcat/jakarta-tomcat-5.5.9/bin/console.txt: I/O error Can someone explain what this error means? thanks, (2 Replies)
Discussion started by: orahi001
2 Replies

3. Shell Programming and Scripting

Unix commands delete all files starting with "X" except "X" itself. HELP!!!!?

im a new student in programming and im stuck on this question so please please HELP ME. thanks. the question is this: enter a command to delete all files that have filenames starting with labtest, except labtest itself (delete all files startign with 'labtest' followed by one or more... (2 Replies)
Discussion started by: soccerball
2 Replies

4. Solaris

How to resolve error "INIT: Cannot stat /etc/inittab, errno: 2"

Hi All, I am getting an error message when I execute command “zlogin -C sunsrv4z5” on my root server. INIT: Cannot stat /etc/inittab, errno: 2 INIT: Cannot stat /etc/inittab, errno: 2 As per my analysis it seems that some files inside /etc folder are deleted. This server was... (14 Replies)
Discussion started by: surbhit4u
14 Replies

5. Solaris

Relation btw commands, "man" and "more" ???

Hi guys, Hope u r doing find. I have this query. When we check the manual pages for a certain command, say man cat we see the manual page with more What is UNIX really doing here, I mean why not less command instead of more command. And can we have UNIX display the manual pages with less command... (2 Replies)
Discussion started by: gabam
2 Replies

6. Red Hat

files having Script which works behind "who" & "w" commands

Dear All, plz print the path of files which have the script of "who" & "w" commands. thnx in advance. (6 Replies)
Discussion started by: saqlain.bashir
6 Replies

7. Shell Programming and Scripting

Intermittent "cp: cannot stat" error with nested loop

I have a bash script that has been running (on SUSE 9.3) dozens of times over the past couple of years without error. Recently it has been hitting intermittent “cp: cannot stat FILE: No such file or directory” errors. The script has nested loops that continuously process files in a... (2 Replies)
Discussion started by: jcart
2 Replies

8. AIX

Equalent of Linux "stat" in AIX

i would like to know the equivalent of stat -c %Y <file> command in AIX. i tried "istat" but its not giving the epoch time and also tried with perl perl -le'printf "%o", 07777 & (stat) for @ARGV' <file> it not also provding the timing . ... (3 Replies)
Discussion started by: expert
3 Replies

9. UNIX for Dummies Questions & Answers

Is "stat: illegal option -- -" an issue with hyphenated filename or flag problem?

Hi. I'm trying to install VMWare Workstation to run a virtual machine on my Mac OS, but running the bundle from bash(xterm) sh VMware-workstation-Full-11.0.0-2305329.x86_64.bundle (as suggested in install guide) comes up with error:stat: illegal option -- - usage: stat Digging... (5 Replies)
Discussion started by: defeated
5 Replies

10. UNIX for Beginners Questions & Answers

Extract delta records using with "comm" and "sort" commands combination

Hi All, I have 2 pipe delimited files viz., file_old and file_new. I'm trying to compare these 2 files, and extract all the different rows between them into a new_file. comm -3 < sort file_old < sort file_new > new_file I am getting the below error: -ksh: sort: cannot open But if I do... (7 Replies)
Discussion started by: njny
7 Replies
ATF-CHECK(1)						    BSD General Commands Manual 					      ATF-CHECK(1)

NAME
atf-check -- executes a command and analyzes its results SYNOPSIS
atf-check [-s qual:value] [-o action:arg ...] [-e action:arg ...] [-x] command DESCRIPTION
atf-check executes a given command and analyzes its results, including exit code, stdout and stderr. Test cases must use atf-sh(3)'s atf_check builtin function instead of calling this utility directly. In the first synopsis form, atf-check will execute the provided command and apply checks specified by arguments. By default it will act as if it was run with -s exit:0 -o empty -e empty. Multiple checks for the same output channel are allowed and, if specified, their results will be combined as a logical and (meaning that the output must match all the provided checks). In the second synopsis form, atf-check will print information about all supported options and their purpose. The following options are available: -s qual:value Analyzes termination status. Must be one of: exit:<value> checks that the program exited cleanly and that its exit status is equal to value. The exit code can be omit- ted altogether, in which case any clean exit is accepted. ignore ignores the exit check. signal:<value> checks that the program exited due to a signal and that the signal that terminated it is value. The signal can be specified both as a number or as a name, or it can also be omitted altogether, in which case any signal is accepted. Most of these checkers can be prefixed by the 'not-' string, which effectively reverses the check. -o action:arg Analyzes standard output. Must be one of: empty checks that stdout is empty ignore ignores stdout file:<path> compares stdout with given file inline:<value> compares stdout with inline value match:<regexp> looks for a regular expression in stdout save:<path> saves stdout to given file Most of these checkers can be prefixed by the 'not-' string, which effectively reverses the check. -e action:arg Analyzes standard error (syntax identical to above) -x Executes command as a shell command line, executing it with the system shell defined by ATF_SHELL. You should avoid using this flag if at all possible to prevent shell quoting issues. EXIT STATUS
atf-check exits 0 on success, and other (unspecified) value on failure. ENVIRONMENT
ATF_SHELL Path to the system shell to be used when the -x is given to run commands. EXAMPLES
The following are sample invocations from within a test case. Note that we use the atf_check function provided by atf-sh(3) instead of exe- cuting atf-check directly: # Exit code 0, nothing on stdout/stderr atf_check 'true' # Typical usage if failure is expected atf_check -s not-exit:0 'false' # Checking stdout/stderr echo foobar >expout atf_check -o file:expout -e inline:"xx yy " 'echo foobar ; printf "xx yy " >&2' # Checking for a crash atf_check -s signal:sigsegv my_program # Combined checks atf_check -o match:foo -o not-match:bar echo foo baz SEE ALSO
atf-sh(1) BSD
October 5, 2014 BSD
All times are GMT -4. The time now is 01:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy