Page 1 of 1

Redirect &>> problem in bash

Posted: Thu Feb 15, 2007 1:47 am
by jyhm

Code: Select all

#These work.
command -flags $variable > myfile.txt
command -flags $variable 2> myfile.txt
command -flags $variable >> myfile.txt
command -flags $variable 2>> myfile.txt
command -flags $variable &> myfile.txt

# But its choking when I do this

command -flags $variable &>> myfile.txt
Anyone have any idea? I need to be able to append both std and std err to the same file.

Posted: Thu Feb 15, 2007 6:06 am
by Jenk

Code: Select all

command -flags $variable 1>> myfile.txt  2>&1

Posted: Thu Feb 15, 2007 2:06 pm
by jyhm
Thanks Jenk,

You truley are a beautiful cow! :D

Is it possible to direct the result of a command into a variable? If the the result is blank I still need to have a place holder so that I can set up an array value as "N/A" or what ever.

Posted: Fri Feb 16, 2007 9:36 am
by Jenk
Yes,

Code: Select all

VARIABLE=`command`

Posted: Fri Feb 16, 2007 10:04 am
by Chris Corbyn
Jenk wrote:Yes,

Code: Select all

VARIABLE=`command`
Or this:

Code: Select all

VARIABLE=$(command)
#works for arrays too
x=$(find . -name '*.*')
#or
y=$(ls -lR)