ksh view std err state


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh view std err state
# 1  
Old 04-01-2012
ksh view std err state

I would like to know if a command works.

"command" 2>/dev/null

When I issue the command, the error is suppressed. How can I tell whether there was an error?
# 2  
Old 04-01-2012
Code:
"command" 2>/dev/null
if [ $? -ne 0 ];then 
echo "error encountered" 
fi

$? store the status of immediate previous executed command.
# 3  
Old 04-01-2012
Query the shell built-in variable "$?" which shows the return code from the previous command. typically the return code will be 0 for success and non-zero for an error.

Code:
#!/bin/ksh
ls xyz 2>/dev/null
if [[ $? > 0 ]]; then
  print error
fi

exit 0

# 4  
Old 04-01-2012
Code:
"command" 2>/dev/null || echo "there was an error (RC=$?)"

Code:
if "command" 2>/dev/null; then 
  echo success
else 
  echo "there was an error (RC=$?)" 
fi


Last edited by Scrutinizer; 04-01-2012 at 06:49 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. What is on Your Mind?

Moving from Desktop View to Mobile View

See attached video for a demo on how to move back and forth from the desktop view to the mobile view. Currently this only works for the home page, but I will work on some new PHP code in the future to make this work with the page we are currently on. Edit: The issue with making every page ... (2 Replies)
Discussion started by: Neo
2 Replies

2. AIX

Open firmware state to running state

Hi Admins, I am having a whole system lpar in open firmware state on HMC. How can I bring it to running state ? Let me know. Thanks. (2 Replies)
Discussion started by: snchaudhari2
2 Replies

3. Shell Programming and Scripting

Keeping std & err outputs alive and feed one log file in a one-shot way

Bonjour, I have a large script with a lot of print statements and misc commands. Standard and error outputs are redirected like into the following code : #!/usr/bin/ksh LOG=/<some dir>/log > $LOG exec >>${LOG} 2>>${LOG} print aaaaa print bbbbb print ccccc ... some_cmd That way,... (5 Replies)
Discussion started by: Fundix
5 Replies

4. Shell Programming and Scripting

Ksh script: std Out/err

Hello gurus, this is part of my script: ls -1 ${MyFile} >> ${dir_log}ListFile${Now}.tmp FILENUM=`cat ${dir_log}ListFile${Now}.tmp| wc -l | awk '{print $1}'`>> /dev/null if then writeError "ERRORE: no file in directory for type ${FileName}!" >> ${LogFileName} Close 1 fi... (7 Replies)
Discussion started by: GERMANICO
7 Replies

5. Shell Programming and Scripting

Help with Getopt::Std

I am working on a script that lists files in a directory with a few file attributes depending on what option the user specifies at the command prompt. The script uses Getopt::Std and takes two switches. The first switch allows the user to specify a directory, the second switch gives a long... (3 Replies)
Discussion started by: Breakology
3 Replies

6. Shell Programming and Scripting

Getting err with 'awk' command

Hi All, I am trying to run the below cmd thro' a script. awk 'NR>=48&&NR<=(58-1)' $IN_FILE_NAME | tee $OUT_FILE_NAME but I am getting an err while running the script. It gives the below err msg : awk: syntax error near line 1 awk: bailing out near line 1 (P.S Note: When run the... (6 Replies)
Discussion started by: askumarece
6 Replies

7. Programming

Sun Studio C++ - Getting error in linking std::ostream &std::ostream::operator<<(std:

Hello all Im using CC: Sun C++ 5.6 2004/07/15 and using the -library=stlport4 when linkning im getting The fallowing error : Undefined first referenced symbol in file std::ostream &std::ostream::operator<<(std::ios_base&(*)(std::ios_base&))... (0 Replies)
Discussion started by: umen
0 Replies

8. Shell Programming and Scripting

how to view html in ksh programm

have a script in ksh called file1 #!/bin/ksh cat my.html --------------------------- and a html file hy.html can u tell me that if i execute "file1" script it will open hy.html bt here it is showing the all the tags along with text......... it should open the browser part... (2 Replies)
Discussion started by: ali560045
2 Replies

9. Shell Programming and Scripting

How to redirect std err and out to log file for multi-commands?

The following command does not work under cygwin bash. ant debug >log 2>&1 && ant image >>log 2>>&1 & pid=$! It gives the error "-bash: sysntax error near unexpected token '&'". Is there a way I can redirect std output and std error to file "log" for both the commands "ant debug" and "ant... (1 Reply)
Discussion started by: siegfried
1 Replies

10. Shell Programming and Scripting

How to redirect std out and std err to same file

Hi I want both standard output and standard error of my command cmd to go to the same file log.txt. please let me know the best commandline to do this. Thanks (2 Replies)
Discussion started by: 0ktalmagik
2 Replies
Login or Register to Ask a Question