Linux find command seems to not transmit all the result to the '-exec command'

Hello.

From a script, a command for a test is use :

 find   /home/user_install   -maxdepth 1    -type f     -newer /tmp/000_skel_file_deb  ! -newer /tmp/000_skel_file_end     -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o -name '.i18n' -o -name '.inputrc'  
 

Tha command return the following in the console screen :

/home/user_install/.bashrc
/home/user_install/.profile
/home/user_install/.i18n
/home/user_install/.inputrc
/home/user_install/.gtkrc-2.0

Within that script the function 'COPY_CHERCHE ' is define as this :

function COPY_CHERCHE () {

    local B_FILE
    local B_FOLDER_OUT
    local B_EXCLUDE
    local B_FILE_OUT
    local MY_DEBUG=1
    FLAG="0"

#    set -x

    B_FILE="$1"
    B_FOLDER_OUT="$2"
    B_EXCLUDE="$3"
    B_FILE_OUT="$4"
    echo "B_FILE        : $B_FILE"
    echo "B_FOLDER_OUT  : $B_FOLDER_OUT"
    echo "B_EXCLUDE     : $B_EXCLUDE"
    echo "B_FILE_OUT    : $B_FILE_OUT"

# +-------------+
# |    BEGIN    |
# +-------------+

    echo
    echo "--"
    echo

# +-----------+
# |    END    |
# +-----------+

}

export -f COPY_CHERCHE

 

Now we change the test command with the real command :

find   /home/user_install   -maxdepth 1    -type f     -newer /tmp/000_skel_file_deb  ! -newer /tmp/000_skel_file_end     -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o -name '.i18n' -o -name '.inputrc'    -exec bash -c 'COPY_CHERCHE  "{}"   /tmp/000_skel_file_folder_PHASE2__2019-04-07___17:23:39     ¤    /tmp/000_skel_file_list_2019-04-07___17:23:39  '  \; 

As tou can see, 4 parameters are sent to the function :

Parameter 1 : the file found by the find command --> "{}"
Parameter 2 : a folder name where to copy the founded file
parameter 3 : the character '¤' which is just flag
parameter 4 : a file where to log operations

My problem is that only one file is taken into account : ''/home/user_install/.inputrc"

Here is my debug output :

!
! +-+-+-+-+-+-+ ENTERING FUNCTION CHERCHE +-+-+-+-+-+-+
!
PATH         :  /home/user_install   -maxdepth 1    -type f 
SEARCH       :  -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o -name '.i18n' -o -name '.inputrc' 
DATE         :   -newer /tmp/000_skel_file_deb  ! -newer /tmp/000_skel_file_end  
EXCLUDE      :  ¤ 
EXCLUDE DIR  : 
FOLDER OUT   :  /tmp/000_skel_file_folder_PHASE2__2019-04-07___18:21:41 
FILE OUT     :  /tmp/000_skel_file_list_2019-04-07___18:21:41 
!
! COMMAND LINE : find   /home/user_install   -maxdepth 1    -type f     -newer /tmp/000_skel_file_deb  ! -newer /tmp/000_skel_file_end     -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o -name '.i18n' -o -name '.inputrc'    -exec bash -c 'COPY_CHERCHE  "{}"   /tmp/000_skel_file_folder_PHASE2__2019-04-07___18:21:41     ¤    /tmp/000_skel_file_list_2019-04-07___18:21:41  '  \; 
!
!


+ eval 'find   /home/user_install   -maxdepth 1    -type f     -newer /tmp/000_skel_file_deb  ! -newer /tmp/000_skel_file_end     -name '\''.bashrc'\'' -o -name '\''.profile'\'' -o -name '\''.gtkrc-2.0'\'' -o -name '\''.i18n'\'' -o -name '\''.inputrc'\''    -exec bash -c '\''COPY_CHERCHE  "{}"   /tmp/000_skel_file_folder_PHASE2__2019-04-07___18:21:41     ¤    /tmp/000_skel_file_list_2019-04-07___18:21:41  '\''  \; '
++ find /home/user_install -maxdepth 1 -type f -newer /tmp/000_skel_file_deb '!' -newer /tmp/000_skel_file_end -name .bashrc -o -name .profile -o -name .gtkrc-2.0 -o -name .i18n -o -name .inputrc -exec bash -c 'COPY_CHERCHE  "{}"   /tmp/000_skel_file_folder_PHASE2__2019-04-07___18:21:41     ¤    /tmp/000_skel_file_list_2019-04-07___18:21:41  ' ';'
%
% +-+-+-+-+-+-+ ENTERING FUNCTION COPY_CHERCHE +-+-+-+-+-+-+
%
+ B_FILE=/home/user_install/.inputrc
+ B_FOLDER_OUT=/tmp/000_skel_file_folder_PHASE2__2019-04-07___18:21:41
+ B_EXCLUDE=¤
+ B_FILE_OUT=/tmp/000_skel_file_list_2019-04-07___18:21:41
+ echo 'B_FILE        : /home/user_install/.inputrc'
B_FILE        : /home/user_install/.inputrc
+ echo 'B_FOLDER_OUT  : /tmp/000_skel_file_folder_PHASE2__2019-04-07___18:21:41'
B_FOLDER_OUT  : /tmp/000_skel_file_folder_PHASE2__2019-04-07___18:21:41
+ echo 'B_EXCLUDE     : ¤'
B_EXCLUDE     : ¤
+ echo 'B_FILE_OUT    : /tmp/000_skel_file_list_2019-04-07___18:21:41'
B_FILE_OUT    : /tmp/000_skel_file_list_2019-04-07___18:21:41
+ echo %
%
+ echo '% +-+-+-+-+-+-+  EXITING FUNCTION COPY_CHERCHE  +-+-+-+-+-+-+'
% +-+-+-+-+-+-+  EXITING FUNCTION COPY_CHERCHE  +-+-+-+-+-+-+
+ echo %
%
+ echo '% +-+-+-+-+-+-+  RETURNING TO FUNCTION CHERCHE  +-+-+-+-+-+-+'
% +-+-+-+-+-+-+  RETURNING TO FUNCTION CHERCHE  +-+-+-+-+-+-+
+ echo %
%
+ echo '!'
!
+ echo '! +-+-+-+-+-+-+ EXITING FUNCTION CHERCHE +-+-+-+-+-+-+'
! +-+-+-+-+-+-+ EXITING FUNCTION CHERCHE +-+-+-+-+-+-+
+ echo '!'
!
+ echo '! +-+-+-+-+-+-+    RETURNING TO MAIN    +-+-+-+-+-+-+'
! +-+-+-+-+-+-+    RETURNING TO MAIN    +-+-+-+-+-+-+
+ echo '!'
!
+ echo '   --- FINISHED ---'
   --- FINISHED ---

 

Any help is welcome

The default between two conditional arguments like -type f or -name xyz is AND.
You can explicitely write -type f -a -name xyz .
The AND makes it necessary to evaluate the second condition if the first condition evaluated TRUE.
The AND has precedence over the -o OR.
If you want to evaluate an OR before an AND you need to work with parenthesis (that must be quoted to escape their special meaning in the shell).

find  /home/user_install  -maxdepth 1  -type f  -newer /tmp/000_skel_file_deb   ! -newer /tmp/000_skel_file_end  \( -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o -name '.i18n' -o -name '.inputrc'  \)  -exec ...
1 Like

Adding -print to the end of your test command, would allow you to more accurately see when the -exec argument would be invoked.

find   /home/user_install   -maxdepth 1    -type f \
       -newer /tmp/000_skel_file_deb  ! -newer /tmp/000_skel_file_end \
       -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o  \
       -name '.i18n' -o -name '.inputrc' \
       -print

vrs

find   /home/user_install   -maxdepth 1    -type f \
       -newer /tmp/000_skel_file_deb  ! -newer /tmp/000_skel_file_end \
       \( -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o  \
          -name '.i18n' -o -name '.inputrc' \) \
       -print
2 Likes

Thank you every body for helping.