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 |
Try
Code:
#!/bin/bash |
old but I thought I would make a correction
Code:
#!/bin/bash |
$ 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 ) |
Code:
#output to stdout aka chan 1 |
I realize this is an old post, but I recently needed this information so I'm posting here for people searching for this in the future.
Quote:
Code:
echo A >1 After some research and experimentation, I found that this works: Code:
[~]# cat ./myscript.sh Code:
[~]# #### Discard stdout... only stderr displays Code:
[~]# echo A Here is some information about my system: Code:
[~]# uname -srvmpio |
The above posts are helpful. Thank you!
I've just been seaching for a way to echo to stderr without disturbing the normal output (stdout).
And finally I got here. Here's my testing results: Code:
$ cat ./stderr_example.sh Some of my system information: Code:
$ uname -srvmpio |
All times are GMT -5. The time now is 05:30 AM. |