Matt Mossholder on 31 Aug 2011 09:41:17 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Bash I/O redirection


On Wed, Aug 31, 2011 at 12:14 PM, Julien Vehent <julien@linuxwall.info> wrote:
On Wed, 31 Aug 2011 11:48:28 -0400, Matt Mossholder wrote:

Julian,
You could try putting blocks of commands inside of parens, which runs
them in a subshell, and then just after the parens, put in your
redirect.

Example:
#!/bin/bash
(
echo "Hi Julien!"
cat /etc/hosts
echo "Bye Julien!"
) 1> /tmp/myoutput 2>&1
That will take all the stdout and stderr and stuff it into
/tmp/myoutput.
--Matt



That might have worked, but I have a switch case somewhere in the code, and the parenthesis from the case conflicts with the parenthesis from the block.


# create a command block to redirect the output
(

# backup
case "$MODE" in
 ÂFULL)
   Â$RMANBIN target / nocatalog << EOF
BACKUP INCREMENTAL LEVEL 0 CUMULATIVE DATABASE TAG 'FULL-$(date +%A)';
EOF


If possible, move the case statement to before the subshell starts. Another possible solution is to have the case statement occur in a function, and have the function reside outside of the subshell. ÂI am sure there must be another way to do this, but that's how I would work it.

  Â--Matt
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug