#!/bin/bash # renameLNX - Korn shell script from UVSI stored in: /home/uvadm/sf/util/ # renameLNX - rename all files in directory to Linux filenaming conventions # - Deleting characters in filenames that must be escaped on Linux systems # - also removing LowBit & HiBit characters using complement option & octal codes # renameLNX1 - original script did not work trying to use "$chars" on the 'tr' command # renameLNX - this HARD-CODEs the HEX chars to be deleted on the 'tr' command & it works # - can anyone tell me how to make "$chars" work on the 'tr' command ??? # echo "rename files in subdir - deleting characters that must be escaped on Linux" dir="$1"; chars="$2"; if [[ -d "$dir" ]]; then : else echo "usage: renameLNX directory " echo " ====================" echo " - arg1=directory, arg2=CharactersToDelete " echo " - arg2 removed for renameLNX, hard-coded on 'tr' comamnd below" echo "\x20\x21\x22\x24\x26\x27\x28\x29\x2A\x2C\x3A\x3B\x3C\x3E\x3F\x5B\x5C\x5D\x7B\x7C\x7D" echo "space \! \" \$ \& \' \( \) \* , : ; < > \? [ \\ ] { | }" exit 1; fi # echo "Remove characters that require escapes on Linux systems (usually none) " x=0; y=0 for dfn in $dir/* do fn1=${dfn##*/} fn2=$(echo $fn1 | tr -cd '\12\40-\176') #remove LowBit&HiBit chars (octal, hex bug optn 'c') fn3=$(echo $fn2 | tr -d \ $'\x20\x21\x22\x24\x26\x27\x28\x29\x2A\x2C\x3A\x3B\x3C\x3E\x3F\x5B\x5C\x5D\x7B\x7C\x7D') #============================= HARD-CODED ============================================== # echo "Debug: fn1=$fn1 fn3=$fn3" let x=x+1 if [[ $fn1 == $fn3 ]]; then continue; fi mv -i "$dir/$fn1" "$dir/$fn3" let y=y+1 echo "file# $x $dir/$fn1 - renamed to: $dir/$fn3" done echo "total $x files, $y renamed " exit 0 #*eject #-------- test renameLNX deletes hardcoded (vs renameLNX1 deletes arg2 & $chars on tr) ------- # renameLNX dirxx # ----- input ----- # file#1=comma=,leftparen=(,rightparen=),exclamation=! # file#2=blanks comma=, leftparen=(, rightparen=), exclamation=! # file#3-exclam=!,dollar=$,amp=&,quotes='",parens=(),star=*,comma=, # ----- renameLNX output OK if deletes hardoded ----- # file#1=comma=leftparen=rightparen=exclamation= # file#2=blankscomma=leftparen=rightparen=exclamation= <-- renameLNX hard-coded OK # file#3-exclam=dollar=amp=quotes=parens=star=comma= # #Note - Also see "renameLNX1" alternate script, deletes as arg2, coded on tr as $chars # # ----- renameLNX1 output BAD when deletes on arg2 & $chars on tr ----- # file#3-eclam=!,dollar=$,amp=&,quotes='",parens=(),star=*,comma=, # file#=blanks comma=, leftparen=(, rightparen=), eclamation=! <-- renameLNX1 NOT working # file#=comma=,leftparen=(,rightparen=),eclamation=! - $arg2 passed to tr ??? # #Note - characters 1,2,x are removed - why is HEX not recognized # - BUT it works if I hard code the 'tr' line as follows: # fn2=$(echo $fn1 | tr -d $'\x21\x24\x26\x27\x28\x29\x2A\x2C') # #=========================================================== # # Why Hard-Coding on 'tr' works, but not substituting as in renameLNX1 ??? # renameLNX1 dirxx '\x20\x21\x22...etc...' <-- renameLNX1 deletes arg2 (tr -d \$"$chars") # ======================================== # fn3=$(echo $fn1 | tr -d \$"$chars") <-- $arg2 on tr does NOT work ??? # #==================================