0

Experts,

Following this question I execute this command:

xargs argument using posix:

find <somePath> -name '*.html' | sort -n | xargs -I{} sh -c 'w3m "{}" &>> "test.log"' --{}

I get the following errors:

  • file.hml: -c: line 0: syntax error near unexpected token `>'
  • file.hml: -c: line 0: `w3m ".html" &>> "test.log"'

Why does bash not understand &>> in my line execution?

As @Nahuel Fouilleul said "sh (posix) doesn't recognize the (bash) redirection &>>".

xargs argument using bash

However the solution proposed is not working when I execute the following command:

find <somePath> -name '*.html' | sort -n | xargs -I{} w3m {} &>> "test.log"

I receive this error:

  • bash: syntax error near unexpected token `>'

Why does bash not understand &>> in my line execution? See my answer

Community
  • 1
  • 1
birdman
  • 211
  • 1
  • 5
  • 13

2 Answers2

2

it may not work if sh (posix) doesn't recognize the (bash) redirection &>>. but the command still can break for certain file names.

Command should be.

.. | xargs -I{} bash -c 'w3m "$1" &>> "test.log"' "process_name_you_want" {}

or to avoid to open log file for each file redirection can be moved out

.. | xargs -I{} w3m {} &>> "test.log"

EDIT: answer is general to a tool which processes files and write to output, after looking at w3m tool it seems it's a web browser in a console, what are you trying to do ?

Nahuel Fouilleul
  • 18,726
  • 2
  • 31
  • 36
  • Thanks I tried the second solution ".. | xargs -I{} w3m {} &>> "test.log" and I receive the following error: bash: syntax error near unexpected token `>'. I have html files in a directory and I would like to dump them in a log file. Therefore I use w3m that displays the information of the html file in the standard output. – birdman Jun 13 '17 at 12:06
1

From here I realized that the operator "&>>" is only available from Bash version 4. I am using Bash version 3.2.51 so it doesn't work.

For versions previous to bash 4 two operators are needed:

w3m >> test.log 2>&1

where:

">>" append stdout to test.log

"2>&1" redirect the stderr to where the sdout is going

So the command working with xargs is the following:

.. | xargs -I{} w3m {} >> "test.log" 2>&1
birdman
  • 211
  • 1
  • 5
  • 13