3 added 67 characters in body
source | link

You do not tell precisely what your script need to achieve but assuming you want to pass each odd file as first argument and each even file name as second argument, here is how to do it a portable way:

t=$(mktemp)
find /tmp/test -name "*.txt" -exec sh -c '
    if [ -s $1 ]
    then
        ./thulac < "$(<$1)" > "/mnt/tokenized/$2"
    else
        printf "%s" "$2" > "$1"
    fi' sh $t {} \;
rm $t

Should you just want pass the path and the filename of every file found, the answer is simpler, still only using a portable commands and syntax (POSIX), i.e. not depending on bash, GNU find and GNU xargs:

find /tmp/test -name "*.txt" -exec sh -c '
    ./thulac < "$1" > "/mnt/tokenized/$(basename "$1")"' sh {} \;

Note that {} need only to be quoted when using the fish shell, a very unlikely eventsituation.

You do not tell precisely what your script need to achieve but assuming you want to pass each odd file as first argument and each even file name as second argument, here is how to do it a portable way:

t=$(mktemp)
find /tmp/test -name "*.txt" -exec sh -c '
    if [ -s $1 ]
    then
        ./thulac < "$(<$1)" > "/mnt/tokenized/$2"
    else
        printf "%s" "$2" > "$1"
    fi' sh $t {} \;
rm $t

Should you just want pass the path and the filename of every file found, the answer is simpler, still only using a portable syntax (POSIX):

find /tmp/test -name "*.txt" -exec sh -c '
    ./thulac < "$1" > "/mnt/tokenized/$(basename "$1")"' sh {} \;

Note that {} need only to be quoted when using the fish shell, a very unlikely event.

You do not tell precisely what your script need to achieve but assuming you want to pass each odd file as first argument and each even file name as second argument, here is how to do it a portable way:

t=$(mktemp)
find /tmp/test -name "*.txt" -exec sh -c '
    if [ -s $1 ]
    then
        ./thulac < "$(<$1)" > "/mnt/tokenized/$2"
    else
        printf "%s" "$2" > "$1"
    fi' sh $t {} \;
rm $t

Should you just want pass the path and the filename of every file found, the answer is simpler, still only using portable commands and syntax (POSIX), i.e. not depending on bash, GNU find and GNU xargs:

find /tmp/test -name "*.txt" -exec sh -c '
    ./thulac < "$1" > "/mnt/tokenized/$(basename "$1")"' sh {} \;

Note that {} need only to be quoted when using the fish shell, a very unlikely situation.

2 added 373 characters in body
source | link

HereYou do not tell precisely what your script need to achieve but assuming you want to pass each odd file as first argument and each even file name as second argument, here is how I wouldto do it a portable way:

t=$(mktemp)
find /tmp/test -name "*.txt" -exec sh -c '
    if [ -s $1 ]
    then
        ./thulac < "$(<$1)" > "/mnt/tokenized/$2"
    else
        printf "%s" "$2" > "$1"
    fi' sh $t {} \;
rm $t

Should you just want pass the path and the filename of every file found, the answer is simpler, still only using a portable syntax (POSIX):

find /tmp/test -name "*.txt" -exec sh -c '
    ./thulac < "$1" > "/mnt/tokenized/$(basename "$1")"' sh {} \;

Note that {} need only to be quoted when using the fish shell, a very unlikely event.

Here is how I would do it a portable way:

t=$(mktemp)
find /tmp/test -name "*.txt" -exec sh -c '
    if [ -s $1 ]
    then
        ./thulac < "$(<$1)" > "/mnt/tokenized/$2"
    else
        printf "%s" "$2" > "$1"
    fi' sh $t {} \;
rm $t

You do not tell precisely what your script need to achieve but assuming you want to pass each odd file as first argument and each even file name as second argument, here is how to do it a portable way:

t=$(mktemp)
find /tmp/test -name "*.txt" -exec sh -c '
    if [ -s $1 ]
    then
        ./thulac < "$(<$1)" > "/mnt/tokenized/$2"
    else
        printf "%s" "$2" > "$1"
    fi' sh $t {} \;
rm $t

Should you just want pass the path and the filename of every file found, the answer is simpler, still only using a portable syntax (POSIX):

find /tmp/test -name "*.txt" -exec sh -c '
    ./thulac < "$1" > "/mnt/tokenized/$(basename "$1")"' sh {} \;

Note that {} need only to be quoted when using the fish shell, a very unlikely event.

1
source | link

Here is how I would do it a portable way:

t=$(mktemp)
find /tmp/test -name "*.txt" -exec sh -c '
    if [ -s $1 ]
    then
        ./thulac < "$(<$1)" > "/mnt/tokenized/$2"
    else
        printf "%s" "$2" > "$1"
    fi' sh $t {} \;
rm $t