Visit Our UNIX and Linux User Community


Bash expansion


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash expansion
# 8  
Old 02-10-2017
Quote:
Originally Posted by jcdole
Thank you very much for your effort.
But I have to draw your attention on two things :
1) FILTER_2 is a list of files and then ".Xauthority,.xsession1,.bash_history" are files.
2) My real problem is when I try to add a second predicate (list of files in FILTER_2) after the first predicate ( FILTER_1 )
This solution has evolved over the weekend but as there have been no further replies I'll update in-place.

My final solution avoids changes of $IFS and the set -f builtin. Firstly an example of the solution using some dummy directories and files in /tmp. Note whitespace is used in $MY_PATH to show this method supports that situation. I also create a file matching .dummy* to highlight any erroneous expansions from PWD:
Code:
$ MY_PATH="/tmp/jc dole"
$ mkdir -p "$MY_PATH"/{test,.local/share/{kscreen,ballo},.dbus}
$ touch "$MY_PATH"/{test,.local/share/{kscreen,ballo},.dbus}/{test{1,2},.direct{A,B,C},.Xauthority,.xsession1,.bash_history}
$ touch .direct_Dummy_PWD_File
$ FA=( -path "$MY_PATH"/.local/share/kscreen -o -path "$MY_PATH"/.local/share/ballo -o -path "$MY_PATH"/.dbus )
$ FB=( ! -name .direct\*  ! -name .Xauthority  ! -name .xsession\*  ! -name .bash_history )

$ find "$MY_PATH"  -type d \( "${FA[@]}" \)  -prune -o -type f \( "${FB[@]}" -print \)
/tmp/jc dole/test/test1
/tmp/jc dole/test/test2

$ rm .direct_Dummy_PWD_File

Below I have updated the original script to use this method.

I'm a little unsure why you have the CHERCHE() function, but have continued to use it below as it could be a simplified stub for the actual function you are using to process these files. However, there is now no need to test for directories at the top of CHERCHE(), as find no longer passes unwanted directory names to the function.

Code:
function CHERCHE () {
    caller="$1"
    shift
    MY_PATH1="$@" 
    echo "doing : $MY_PATH1"
    /usr/bin/kate "$MY_PATH1"
}
export -f CHERCHE

MY_PATH="/home/bidon"

FILTRE_1=( -path  "$MY_PATH"/.local/share/kscreen  -o -path  "$MY_PATH"/.local/share/baloo -o -path  "$MY_PATH"/.dbus )
FILTRE_2=( ! -name .direct\*  ! -name .Xauthority  ! -name .xsession\*  ! -name .bash_history )

find "$MY_PATH"  -type d \( "${FILTRE_1[@]}" \)  -prune -o -type f \( "${FILTRE_2[@]}" -exec bash -c "CHERCHE \"$0\" {}" \; \)


Last edited by Chubler_XL; 02-12-2017 at 05:00 PM..
This User Gave Thanks to Chubler_XL For This Post:
# 9  
Old 02-14-2017
I will test it and give you news as soon as possible.

---------- Post updated 14-02-17 at 13:02 ---------- Previous update was 13-02-17 at 19:49 ----------

Quote:
Originally Posted by Chubler_XL
.......
Code:
find "$MY_PATH"  -type d \( "${FILTRE_1[@]}" \)  -prune -o -type f \( "${FILTRE_2[@]}" -exec bash -c "CHERCHE \"$0\" {}" \; \)

Congratulation !

That do the job.

Thank you very much indeed.

Smilie

Previous Thread | Next Thread
Test Your Knowledge in Computers #235
Difficulty: Easy
The ARPANET was operated by the military during the two decades of its existence, until 1990.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use parameter expansion over a parameter expansion in bash.

Hello All, Could you please do help me here as I would like to perform parameter expansion in shell over a parameter expansion. Let's say I have following variable. path="/var/talend/nat/cdc" Now to get only nat I could do following. path1="${path%/*}" path1="${path1##*/}" Here... (8 Replies)
Discussion started by: RavinderSingh13
8 Replies

2. Shell Programming and Scripting

Bash : More parameter expansion and IFS

I am trying to become more fluent with the interworking of bash and minimize the number of external calls. Sample Data. This will be the response of the snmp query. SNMPv2-MIB::sysName.0 = STRING: SomeHostName SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::enterprises.9.1.1745... (5 Replies)
Discussion started by: sumguy
5 Replies

3. Shell Programming and Scripting

Bash Parameter Expansion

#!/bin/bash SNMPW='/usr/bin/snmpwalk' while read h i do loc=$($SNMPW -v3 -u 'Myusername' -l authPriv -a SHA -A 'Password1' -x AES -X 'Password2' $i sysLocation.0 2>/dev/null) loc=${loc:-" is not snmpable."} loc=${loc##*: } loc=${loc//,/} echo "$i,$h,$loc" done < $1 My question is ... ... (1 Reply)
Discussion started by: sumguy
1 Replies

4. Shell Programming and Scripting

Bash Parameter Expansion

I have made the following examples that print various parameter expansions text: iv-hhz-sac/hpac/hhz.d/iv.hpac..hhz.d.2016.250.070018.sac (text%.*): iv-hhz-sac/hpac/hhz.d/iv.hpac..hhz.d.2016.250.070018 (text%%.*): iv-hhz-sac/hpac/hhz (text#*.): d/iv.hpac..hhz.d.2016.250.070018.sac... (2 Replies)
Discussion started by: kristinu
2 Replies

5. Shell Programming and Scripting

Bash variable expansion

Hello. The file /etc/fstab contains UUID=957c3295-9944-1593-82e2-2b90dede4312 / ext4 noatime,discard,acl,user_xattr 1 1 I fill a variable SOME_LINE=$( cat /etc/fstab | grep \/\..*ext4 | grep noatime,discard )echo $SOME_LINE... (3 Replies)
Discussion started by: jcdole
3 Replies

6. Shell Programming and Scripting

Bash shell expansion help

This is what I have in my directory. $ ls test1.txt test2.txt test3.txt test4.txt test5.txt test_script.sh This is what my shellscript looks like. #!/bin/bash for filename in /shell_expansion/*.txt; do for ((i=0; i<=3; i++)); do echo "$filename" ... (5 Replies)
Discussion started by: cokedude
5 Replies

7. Shell Programming and Scripting

Does SH support indirect expansion like BASH?

Hello, is there a kind soul who can answer me, does the SH support double substitution known as indirect expansion similar to BASH? The syntax for bash is ${!var}. For instance in bash I can write something like this: VAR="value" REF_VAR="VAR" echo ${!REF_VAR} and get the "value"... (1 Reply)
Discussion started by: dimentiy
1 Replies

8. Shell Programming and Scripting

Bash variable delayed expansion?

i write a batch file , here is the content. dirname='date +%Y-%m-%d' mkdir dirname but it doen's work, it just create a folder named date and +%Y-%m-%d. i have tried run the command seperately in the bash prompt. after the first sentence executed , i use $dirname to watch the value of... (4 Replies)
Discussion started by: premotheus
4 Replies

9. Shell Programming and Scripting

Brace expansion problem in Bash

I have a script that takes an option for server pools to run the script against. The option is given as a comma separated list (ie, -p 201,204,301). I'm using eval and brace expansion to get those pool numbers into an array. It works fine unless only 1 pool number is given. Here's the code: ... (5 Replies)
Discussion started by: mglenney
5 Replies

10. Shell Programming and Scripting

bash - delay expansion of variable

Hello - I have a bash script which does some logging, and I'd like to include the line number of the echo statement that pipes into $LOGGER: MYPID=$$ MYNAME=`basename $0` LOGGER="/usr/bin/logger -t $MYNAME($LINENO) -p daemon.error" ... echo 'this is an entry into the log file' | $LOGGER ... (3 Replies)
Discussion started by: scandora
3 Replies

Featured Tech Videos