I'm writing a small script that will help me debug some permission problems. I am passing the parent folder I wish to examine and am able to specify any sub-folders which I want to ignore.
I'm having a problem passing the constructed parameter string to find because some parts of it (the are being escaped. I can't seem to figure out how to provide the wildcard into the command in such a way that find accepts it properly. With the wildcard in place, that portion of the path string is qualified using single quotes that are escaped using '\'' and are confusing me (as I can't figure out how to control the transformation) and find (which is essentially ignoring my excludes)
I've been reading all about single and double quotes as well as escaping characters, but I haven't found an example similar to mine.
#!/bin/bash -f
# output permissions and ownership with path relative to specified parent.
Usage="$0 <parent path> <excluded child folder> ...."
if [ $# -lt 1 ]
then
(>&2 echo -e $Usage)
exit 1
else
parent=$1
shift
if [ $# -gt 0 ]
then
excludes=" ("
for folder in $@
do
thisLine=" ! -path $parent$folder ! -path '$parent$folder/*'" <=== the '*' wildcard is causing the problem I think.
excludes=$excludes$thisLine
done
excludes=$excludes" )"
fi
(>&2 echo "=> find $parent $excludes -ls | awk '{print "'$3"|"$5"|"$6"|"$11}'"'")
(>&2 echo )
set -vx
find $parent $excludes -ls | awk '{print $3"|"$5"|"$6"|"$11}'
fi
The branch of the tree that I'm working with is /home/user/catkin_ws/src/clfsm which has three sub-folders, two of which I wish to exclude; cmake & include. The output below is in two parts: Top is the current output, which does not filter the folders I wish to exclude. The bottom part is correct, using the echoed command line from my code above.
The command to call the above script is:
~/myScripts/show_permissions.sh /media/nap/U14041/home/nap/catkin_ws/src/clfsm /cmake /include. Note that Stephen's solution requires that the sub-folders to be excluded be specified without a leading /.
user@rMBP-Ubuntu:[12:29]:/home/user/catkin_ws/src/clfsm$ ~/myScripts/show_permissions.sh /home/user/catkin_ws/src/clfsm /cmake /include
=> find /home/user/catkin_ws/src/clfsm ( ! -path /home/user/catkin_ws/src/clfsm/cmake ! -path '/home/user/catkin_ws/src/clfsm/cmake/*' ! -path /home/user/catkin_ws/src/clfsm/include ! -path '/home/user/catkin_ws/src/clfsm/include/*' ) -ls | awk '{print $3"|"$5"|"$6"|"$11}'
++ find /home/user/catkin_ws/src/clfsm '(' '!' -path /home/user/catkin_ws/src/clfsm/cmake '!' -path ''\''/home/user/catkin_ws/src/clfsm/cmake/*'\''' '!' -path /home/user/catkin_ws/src/clfsm/include '!' -path ''\''/home/user/catkin_ws/src/clfsm/include/*'\''' ')' -ls
++ awk '{print $3"|"$5"|"$6"|"$11}'
drwxrwxr-x|user|user|/home/user/catkin_ws/src/clfsm
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/clfsm.layout
drwxrwxr-x|user|user|/home/user/catkin_ws/src/clfsm/src
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/src/clfsm_visitorsupport.cc
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/src/clfsm_machine.cc
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/src/clfsm_visitors.cc
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/src/clfsm_main.cc
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/src/clfsm_cc.cc
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/cmake/FindLibDispatch.cmake
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/CMakeLists.txt
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/clfsm_vector_factory.h
drwxrwxr-x|user|user|/home/user/catkin_ws/src/clfsm/include/typeClassDefs
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/typeClassDefs/FSMControlStatus.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/typeClassDefs/FSM_Control.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/typeClassDefs/wb_fsm_control_status.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/typeClassDefs/wb_fsm_state_status.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/CLActionAction.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/FSMWBQueryPredicate.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/FSMSuspensibleMachine.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/FSMWBSubMachine.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/gu_util.h~
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/CLTransitionExpression.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/FSMWBContext.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/FSMState.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/FSMAction.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/FSMExpression.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/clfsm_cc.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/FSMTransition.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/clfsm_visitorsupport.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/stringConstants.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/clfsm_factory.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/FSMFactory.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/FSMachineVector.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/FSMActivity.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/clfsm_visitors.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/FSMachine.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/clfsm_cc_delegate.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/clfsm_machine.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/gu_util.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/FSMWBPredicate.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/clfsm_wb_vector_factory.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/include/FSM.h
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/package.xml
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/clfsm.cbp
user@rMBP-Ubuntu:[12:34]:/home/user/catkin_ws/src/clfsm$ find /home/user/catkin_ws/src/clfsm \( ! -path /home/user/catkin_ws/src/clfsm/cmake ! -path '/home/user/catkin_ws/src/clfsm/cmake/*' ! -path /home/user/catkin_ws/src/clfsm/include ! -path '/home/user/catkin_ws/src/clfsm/include/*' \) -ls | awk '{print $3"|"$5"|"$6"|"$11}'
drwxrwxr-x|user|user|/home/user/catkin_ws/src/clfsm
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/clfsm.layout
drwxrwxr-x|user|user|/home/user/catkin_ws/src/clfsm/src
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/src/clfsm_visitorsupport.cc
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/src/clfsm_machine.cc
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/src/clfsm_visitors.cc
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/src/clfsm_main.cc
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/src/clfsm_cc.cc
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/CMakeLists.txt
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/package.xml
-rw-rw-r--|user|user|/home/user/catkin_ws/src/clfsm/clfsm.cbp
user@rMBP-Ubuntu:[12:35]:/home/user/catkin_ws/src/clfsm$