Batch rename files using mv and sed within a for loop results in exit code 64 - How do I correct the script? -


i attempting rename several hundred folders remove numbers prefixed folder name. seem have gotten of way there, script not quite work yet. when echo commands created script instead of running commands, looks fine. script:

for file in *     echo mv "'"$file"'" $(echo "'"$file"'" | sed 's/[0-9]\{1,3\} //') done 

returns many lines of:

mv '123 filename' 'filename' mv '99 name' 'another name' . . . etc. 

if take 1 of lines , use on command line, folder renamed appropriately. if remove echo run mv commands, though, not work. instead, mv prints out usage reminder comes when incorrectly enter command in way.

why output commands work individually not within loop? how can correct script?

your quoting looks oddball. variable should in double quotes, no more , no less.

furthermore, should avoid brittle $(echo ... | sed ...); can accomplished in pure shell:

for f in *;     g=${f#[0-9]}; g=${g#[0-9]}; g=${g#[0-9]}     echo mv "$f" "${g# }" done 

run sh -x if want verify echo gets correct quoting. remove echo move.

the reason output worked when copy/pasted second level of quoting necessary when copying output echo. (risky, convoluted) workaround have been replace echo eval.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -