LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
LinkBack Search this Thread
Old 04-03-2007, 02:10 AM   #1
colonel_t
LQ Newbie
 
Registered: Apr 2007
Posts: 1

Rep: Reputation: 0
Bash Scripting: Echo to Standard Error


Hi all.

I'm trying to print out all arguments passed to a script on a single line sent to STDERR


My script:

#!/bin/bash
echo $* >&2


Am I missing something? I know that >&2 should send STDERR to whatever is after it, but do I need to specify that the line is an error or something?


Thanks
 
Old 04-03-2007, 06:02 AM   #2
Centinul
Member
 
Registered: Jun 2005
Distribution: Gentoo
Posts: 552

Rep: Reputation: 30
Try

Code:
#!/bin/bash
echo "$*" >&2
Hope this helps!
 
Old 01-20-2011, 01:22 PM   #3
mikemcdonough
LQ Newbie
 
Registered: Jan 2005
Location: North Carolina
Distribution: FC4
Posts: 6

Rep: Reputation: 0
old but I thought I would make a correction

Code:
#!/bin/bash
echo $* 1>&2
 
0 members found this post helpful.
Old 07-11-2011, 01:12 PM   #4
lineus
LQ Newbie
 
Registered: Jul 2011
Posts: 1

Rep: Reputation: Disabled
$ cat myscript.sh
#!/bin/bash
# not sure how portable this is, but it works on rhel 5.4

echo "$*" >/dev/stderr

$ ./myscript.sh unix is fun
unix is fun
$ ./myscript.sh unix is fun 2>~/testing_dev_stderr
$
$ cat ~/testing_dev_stderr
unix is fun


OR


$ cat myscript.sh
#!/bin/bash
# perhaps a more portable way

echo "$*" >/dev/fd/2

$ ./myscript.sh unix is fun
unix is fun
$ ./myscript.sh unix is fun 2>~/testing_dev_stderr
$
$ cat ~/testing_dev_stderr
unix is fun


I suppose the bottom line is that STDERR should be
available to you in the form of a file ( like just about everything else in unix/linux )
 
Old 07-12-2011, 01:16 AM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.2, Centos 5.8
Posts: 11,740

Rep: Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905
Code:
#output to stdout aka chan 1
# 2 methods: NB default is stdout (chan 1) anyway ...
echo A 
echo A >1

# output to stderr aka chan 2
echo B >2

# output to both
# 2>&1 => output stderr (chan 2)to same chan (&) as stdout (chan 1)
echo C >1 2>&1
echo C 2>&1

# chan 0 is stdin
 
  


Reply

Tags
bash, echo, stderr


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH scripting I/O redirection error blinux1 Programming 13 03-18-2008 08:21 PM
Bash Scripting - echo command question gbhil Programming 2 04-27-2005 07:27 PM
BASH scripting error Darklight451 Linux - General 4 11-22-2004 03:59 PM
How do I echo to both standard out and to a file? Br. Nicholas Linux - General 11 10-12-2004 03:09 PM
bash scripting - suppress error messages? brian0918 Programming 2 06-19-2003 11:16 AM


All times are GMT -5. The time now is 02:01 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration