Handling standard error in condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Handling standard error in condition
# 8  
Old 12-23-2013
I just edited #6please use last code that will work for you with ksh.

Last edited by Akshay Hegde; 12-23-2013 at 07:45 AM..
This User Gave Thanks to Akshay Hegde For This Post:
# 9  
Old 12-23-2013
Yup it works... Thanks!

But now i really want to know how to break down your lines Smilie

You are putting standard error in /dev/null ... ok got that but why standard output to wc -l?

So if it doesn't find anything (it won't give you a line hence will return 0 on wc -l and thuss will not be greater than 0)

Can't beleive there isn't something easier .... lol. Will still search around. Thanks again!
# 10  
Old 12-23-2013
Sorry for late reply

without wc you can redirect both error and output

I will create file toto just for testing purpose
Code:
$ touch toto

Code:
$ cat test.ksh
#!/bin/ksh
set -A services "toto" "titi" "tata" "/etc/redhat-release" "tete"
i=0
while [ ${#services[*]} -gt $i ];do
if ls "${services[$i]}" > /dev/null 2>&1; then
    echo "mycode goes here"
else 
    echo "no...some command"
fi;
((i+=1))
done

Code:
$ ksh test.ksh 
mycode goes here
no...some command
no...some command
no...some command
no...some command

This User Gave Thanks to Akshay Hegde For This Post:
# 11  
Old 12-23-2013
Works again.... wonder why doesn't seem to work with the test brackets. Thanks again!
# 12  
Old 12-23-2013
with bracket I think you can check exit status like this

Code:
ls "${services[$i]}" > /dev/null 2>&1
if [ $? -eq  0 ]; then 
    echo "true";
else 
    echo "false"
fi

This User Gave Thanks to Akshay Hegde For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Error handling

Hello fellow UNIX gurus :) I have a problem regarding the script below: # Variables used in this shell. power=0 # Stores squared integer total=0 # Sum of all squared integers num=0 # Stores command line arguements # Provides error handling if command line... (5 Replies)
Discussion started by: Learn4Life
5 Replies

2. Shell Programming and Scripting

Error Handling

Below code works for different databases i.e. MYSQL and ORACLE The problem is for MYSQL in Block: if ; $? taking value accordingly but in case of ORACLE $? is always taking this value as zero (0). That is the reason in Oracle it always going in else Block in any case.. :( and in case of ... (4 Replies)
Discussion started by: ambarginni
4 Replies

3. Shell Programming and Scripting

Standard out and standard error

I need to run a cronjob and in the cronjob I execute a script that if there is an error produces standard error so I do /RUNMYSCRIPT 2> mylogfile.log However, if it runs correctly, I don't get a standard error output, I get a standard out output. How do I redirect both standard error and... (2 Replies)
Discussion started by: guessingo
2 Replies

4. Shell Programming and Scripting

Redirecting standard error issues.

Hello Friends, Good Day. I am trying to redirect a standard error to the bit bucket(/dev/null) but it is not working. Though, it is working fine in redirecting the standard output. Below is the output of my script without any redirection: $ ./CheckVSSLocks.sh... (16 Replies)
Discussion started by: singh.chandan18
16 Replies

5. UNIX for Dummies Questions & Answers

Redirect Standard output and standard error into spreadsheet

Hey, I'm completely new at this and I was wondering if there is a way that I would be able to redirect the log files in a directories standard output and standard error into and excel spreadsheet in anyway? Please remember don't use too advanced of terminology as I just started using shell... (6 Replies)
Discussion started by: killaram
6 Replies

6. Shell Programming and Scripting

Error Handling

Helo Experts, I need a help in handling errors in shell script, wants my errors displayed in text file instead of command window.. My shell script is here; cd /cygdrive/s/Files for FILES in ./*.* do temp=`basename $FILES` if cp $FILES /cygdrive/r/CopyFile1/$FILES; then echo "copy... (5 Replies)
Discussion started by: CelvinSaran
5 Replies

7. Shell Programming and Scripting

Writing to standard error

Hi, I want to redirect the standard output to standard error whenever an error occurs for ex if then echo right else echo wrong fi I want to redirect the wrong to stderror .Adding a line 1>&2 will do that or is additional code to be added.How can i verify whether the output... (2 Replies)
Discussion started by: padmisri
2 Replies

8. Shell Programming and Scripting

standard error to standard out question

Hi there how can i get the result of a command to not give me its error. For example, on certain systems the 'zfs' command below is not available, but this is fine becaues I am testing against $? so i dont want to see the message " command not found" Ive tried outputting to /dev/null 2>&1 to no... (5 Replies)
Discussion started by: hcclnoodles
5 Replies

9. UNIX for Dummies Questions & Answers

Writing to Standard Error

Hi. I'm working on a project for a class, and there's one part of the project that is confusing me. It's a compression and decompression project, and after we write our code for compression, we need to write to standard error. (1) Size of original file (number of characters read... (1 Reply)
Discussion started by: sjung10
1 Replies

10. UNIX for Dummies Questions & Answers

Error: Internal system error: Unable to initialize standard output file

Hey guys, need some help. Running AIX Version 5.2 and one of our cron jobs is writing errors to a log file. Any ideas on the following error message. Error: Internal system error: Unable to initialize standard output file I'm guessing more info might be needed, so let me know. Thanks (2 Replies)
Discussion started by: firkus
2 Replies
Login or Register to Ask a Question