0

I am little bit confused about redirections in linux.

  1. command > file

  2. command 1> file

  3. command >> file.out 2>> file.err (this is working as expected)

  4. commmand 1>>file.out 2>>file.err (if command is successful , we get output log of command in file.err instead of in file.out

some guys said > and 1> are same but when used with commands not getting proper output.

for example ,

pg_dump -d postgres -t schemaname.table -v -f table.sql   >>table.out 2>>table.err 

if I execute above command , if command is successful , it should log the logs to table.log and not in table.err . table.err we get logs only in case pg_dump status exit 1.

My expectation is we get log in table.out when pg_dump executed without any error while dumping tables. and we should get logs in table.err when pg_dump status is exit 1 or it's failed to dump tables.

Thanks!

muru
  • 69,900
  • 13
  • 192
  • 292
  • 2
    I get right results - please post real command that you use when you get this behaviour. To the other part of your question '>' and '1>' - as I know they are the same. – Damir Oct 22 '21 at 13:54
  • https://wiki.bash-hackers.org/howto/redirection_tutorial will answer all your concerns. – Aaron D. Marasco Oct 22 '21 at 14:33
  • 3
    _"not getting proper output"_ ... so, what would the proper output be, in this particular case? What output do you expect to get, and what do you get instead? What does `command` do? We could explain what `>`, `1>`, `>>` and `1>>` do, and quote the [manuals](https://www.gnu.org/software/bash/manual/html_node/Redirections.html) and the [standard](https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/utilities/V3_chap02.html#tag_18_07), but I wonder if it would help more to be able to tie that to your situation. – ilkkachu Oct 22 '21 at 15:33
  • I think you don't understand what stderr is. It's not just for "logs only in case pg_dump status exit 1" - applications are free to use stderr for informational or diagnostic logging, prompts, and other things. – muru Oct 22 '21 at 21:19
  • You need to read a basic book about unix and do the programming samples, at least to some degree. theres all kind of fundamentals that you need to understand to start programming. – john-jones Oct 23 '21 at 11:46

0 Answers0