Using "find" and "-exec rm" ... Just no luck :(


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using "find" and "-exec rm" ... Just no luck :(
# 43  
Old 09-03-2009
I'm afraid you refuse to face the evidence so I'm giving up trying to help you understanding where your reasoning fails and why this isn't academic.

There are people that are grateful they are teach something and other people that can't accept being wrong. Looks like you want to be in the second category.

It reminds me those people claiming landing on the moon was faked. I never waste my time discussing with them.
# 44  
Old 09-03-2009
I think we had better agree to differ.

When I come across it again I'll gather evidence and re-post. If you manage to prove that no version of unix or Linux ever exhibits this anomolous behaviour, please re-post.

This has been entertaining if nothing else and I bookmarked some useful reference works along the way (many not posted in this thread).
I even fished some of my archive unix manuals out of storage where I could not find a copy on the Internet. I also re-visited the "find ... -exec" version which crashes unix to find out when they changed the implementation.

I haven't worked on every version of unix but I have worked on rather too many unix variants to believe in standard behaviour!

Thanks for the debate.

methyl
# 45  
Old 09-03-2009
Quote:
Originally Posted by methyl
If you manage to prove that no version of unix or Linux ever exhibits this anomolous behaviour, please re-post.
I already demonstrated it many times.
It is impossible for a command (find) to process something differently (the file names with embedded spaces) depending on something (the quotes) there is no way for the command to know about (because the quotes have been stripped by the shell before passing the curly braces argument to the command to be run later).
# 46  
Old 09-03-2009
I hope I'm not missing something already cleared/explained, but, as far as the filenames with embedded IFS characters are concerned (a space in the example below), and as already mentioned (see note for embedded {} usages before in the thread), a {} quoting might be needed, depending on the syntax used:

Code:
zsh-4.3.10[t]% touch 'a b'                          
zsh-4.3.10[t]% ls   
a b
zsh-4.3.10[t]% find -type f -exec sh -cx 'f={}'  \; 
+ f=./a
+ b
sh: b: command not found
zsh-4.3.10[t]% find -type f -exec sh -cx 'f="{}"'  \;
+ f='./a b'

And, of course, you can write if differently;

Code:
zsh-4.3.10[t]% find -type f -exec sh -cx 'f=$1' inline  {} \; 
+ f='./a b'

# 47  
Old 09-03-2009
(Okay I know I signed off from this thread). Interesting radoulov. Looks different from issues with say renaming files using embedded {} syntax where this syntax is valid: "find .... -exec mv {} {}.txt".
# 48  
Old 09-04-2009
radoulov: the syntax you use in your first examples is a different case than the one this thread is about. (Glad to agree with Methyl on this Smilie )

It also breaks the standard a couple of times so is in the undefined behavior area. i.e. it might work or not depending on the find implementation.

POSIX states:

- the path must not be empty
- the curly braces must appear alone to be processed

It will work in a Gnuish environment but with a POSIX compliant shell and find you might get the following:
Code:
$ find -type f -exec sh -cx 'f={}'  \; 
find: illegal option -- t
find: [-H | -L] path-list predicate-list
$ find . -type f -exec sh -cx 'f={}'  \;
+ f='{}'

The last example is a portable way to achieve the same, although the inline trick might be puzzling and is unnecessary:
Code:
$ find . -type f -exec sh -cx 'f=$1' inline  {} \;
+ f='./a b'
$ find . -type f -exec sh -cx 'f=$0' {} \;
+ f='./a b'



---------- Post updated at 11:57 ---------- Previous update was at 11:51 ----------

Quote:
Originally Posted by methyl
renaming files using embedded {} syntax where this syntax is valid: "find .... -exec mv {} {}.txt".
Too bad this syntax breaks POSIX twice too:
- if {} appear more than once, behavior is unspecified
- it is processed if passed as a two characters argument
# 49  
Old 09-04-2009
Quote:
Originally Posted by jlliagre
radoulov: the syntax you use in your first examples is a different case than the one this thread is about. (Glad to agree with Methyl on this Smilie )

It also breaks the standard a couple of times so is in the undefined behavior area. i.e. it might work or not depending on the find implementation.

POSIX states:

- the path must not be empty
- the curly braces must appear alone to be processed
Sorry,
I didn't understand that the thread was about the standard, I was replying to this statement:

Quote:
It is impossible for a command (find) to process something differently (the file names with embedded spaces) depending on something (the quotes)[...]
Anyway, the first point (about the path) is irrelevant in this case, it was a quick and dirty way to demonstrate the point.

Quote:
It will work in a Gnuish environment but with a POSIX compliant shell and find you might get the following:
Code:
$ find -type f -exec sh -cx 'f={}'  \; 
find: illegal option -- t
find: [-H | -L] path-list predicate-list
$ find . -type f -exec sh -cx 'f={}'  \;
+ f='{}'

As I already said, the poit about the predicate is irrelevant and I didn't consider the standard for this example.

Quote:
The last example is a portable way to achieve the same, although the inline trick might be puzzling and is unnecessary:
Code:
$ find . -type f -exec sh -cx 'f=$1' inline  {} \;
+ f='./a b'
$ find . -type f -exec sh -cx 'f=$0' {} \;
+ f='./a b'

Well,
it could be necessary if, for some reason, you need to name your script/label your code (and use that name/label later).




Last edited by radoulov; 09-04-2009 at 09:14 AM.. Reason: clarified
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. Shell Programming and Scripting

find . -path "*_nobackup*" -prune -iname "*.PDF" \( ! -name "*_nobackup.*" \)

These three finds worked as expected: $ find . -iname "*.PDF" $ find . -iname "*.PDF" \( ! -name "*_nobackup.*" \) $ find . -path "*_nobackup*" -prune -iname "*.PDF" They all returned the match: ./folder/file.pdf :b: This find returned no matches: $ find . -path "*_nobackup*" -prune... (3 Replies)
Discussion started by: wolfv
3 Replies

4. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

5. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

9. UNIX for Dummies Questions & Answers

No utpmx entry: you must exec "login" from lowest level "shell"

Hi I have installed solaris 10 on an intel machine. Logged in as root. In CDE, i open terminal session, type login alex (normal user account) and password and i get this message No utpmx entry: you must exec "login" from lowest level "shell" :confused: What i want is: open various... (0 Replies)
Discussion started by: peterpan
0 Replies
Login or Register to Ask a Question