?
Solved

define a custom error message

Posted on 2003-03-25
5
Medium Priority
?
317 Views
Last Modified: 2010-04-21
Hi All,

How to define a custom error message to stderr?

I don't want to use redirect standard output to a file!

Thanks a lot!

best regards,
dp
0
Comment
Question by:d_p2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:rob-g
ID: 8202136
To output on stderr redirect the command output to file descriptor 2, e.g.

echo "ERROR:..." >&2
0
 

Author Comment

by:d_p2
ID: 8202269
hi rob-g,

i wrote a shell script, test.sh:

/bin/bash
echo "error">&2
exit 0

when i test it in shell
#./test.sh 2>test.error

it simply hang in the console, how to solve it?

Thanks

regards,
dp
0
 
LVL 1

Accepted Solution

by:
rob-g earned 400 total points
ID: 8202323
The details that I gave do work in Korn shell, i.e the script would be

=====================
#!/bin/ksh
echo "ERROR" >&2
exit 0
=====================

Maybe you need to hash-bang (#!) your /bin/bash line.

Otherwise I can't help as I don't use bash and I don't know how if it handles file descriptors differently.
0
 
LVL 5

Expert Comment

by:ecw
ID: 8204044
Like rob-g says, you need the #! /bin/bash.  Otherwise the first thing the script will do is start another invocation of bash, which IIRC, displays prompt to stderr, which you've redirected and thus never see.
0
 

Author Comment

by:d_p2
ID: 8207416
Hi rob-g,

You are right, i forget to place #!  
Thanks a lot!

regards,
dp
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question