I'd like to find fullpath and filename of all
find /mnt/test -name "*.txt" -print0 |xargs -l bash -c './thulac < $0'
echo argument1 argument2 argument3 | xargs -l bash -c 'echo this is first:$0 second:$1 third:$2' | xargs
find /mnt/test -name "*.txt" -print0 -printf "%f" |xargs -l bash -c './thulac < $0 > $1'
-print0 -printf "%f"
/mnt/test/1.txt: $1: ambiguous redirect
The problem is you are not de-limiting the output of
find. It appends a
\0 at end of each file name returned, which has to be read with the same delimiter, which
-0 option in
GNU xargs does.
-print0 options means from the
man find page,
print the full file name on the standard output, followed by a null character (instead of the newline character that -print uses). This allows file names that contain newlines or other types of white space to be correctly interpreted by pro‐ grams that process the find output. This option corresponds to the -0 option of xargs.
-0 to de-limit the output from
find with a proper process-substitution syntax as
#!/bin/bash while IFS= read -r -d '' file; do echo "$file" # '$file' will have the file-name, use it however way you want # to use it done< <(find /mnt/test -name "*.txt" -print0)