Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I was studying a bash script code where I encountered operator "&>>". I didn't understand its use. So, I referred to http://www.gnu.org/software/bash/manual/html_node/Redirections.html .

It is semantically equivalent to >> file 2>&1 .

Following is the output from my shell :-

# echo $SHELL
/bin/bash
# echo "hello" &>> file1
bash: syntax error near unexpected token `>'

and

# echo "hello" >> file1 2>&1

# cat file1 

hello

Question :- Why am I getting error bash: syntax error near unexpected token '>' ?

[EDIT] :- Bash version 3.2.25(1)-release (x86_64-redhat-linux-gnu)

share|improve this question
3  
What version of Bash are you using? Some of these features are only available in newer versions of Bash. –  slm Oct 29 '13 at 14:57
    
BTW, this works for me, bash --version = 4.1.7(1)-release (x86_64-redhat-linux-gnu). –  slm Oct 29 '13 at 15:00

2 Answers 2

up vote 3 down vote accepted

You are getting that error because you using an older version of bash (3.2.25).

Since Bash4, there's &>>TARGET, which is equivalent to >> TARGET 2>&1.

Source: Appending redirected output

So, you should take in consideration an upgrade. I use bash version 4.2.45 and echo "hello" &>> file1 works like a charm for me.

share|improve this answer

This feature was introduced in bash 4.0 alpha, so it should be available in any bash >= 4.0.

http://git.savannah.gnu.org/cgit/bash.git/tree/CHANGES?id=0001803f0b9523c94fa2ede48eaecb047fef4524 -- line 976.

(The original 4.0-alpha changelog mis-reported the operator as >>&. The man page shows the correct &>>, and the typo was corrected in 4.1.)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.