To: bug-coreutils.org
From: Owen Townsend, [email protected]
Date: Nov.05/2019
Subject: 'tr' BUG using complement option with delete chars in HEX vs OCTAL
fn2=$(echo $fn1 | tr -cd '\12\40-\176') #<-- OCTAL works, but HEX
preferred
fn2=$(echo $fn1 | tr -cd \$'\x0A\x20-\x7E') #<-- HEX does not work
See attached scripts renameOK & renameOKx
renameOK - octal coding, works OK
renameOKx - HEX coding does NOT work
- see test results coded as #comments at end of script
Please let me know if you confirm this is a bug and when it might be fixed ?
I am using Ubuntu 16.04 & plan to upgrade to 20.04 when available
Thanks, Owen
#!/bin/bash
# renameOK - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
# renameOK - rename all files in directory, using tr -cd & OCTAL characters
(works OK)
# - Deleting all LowBit (except LineFeed) & HighBit characters
# renameOKx <-- Alternate script specifies delete chars in HEX, but does NOT
work ???
# --> see $UV/sf/util/renameOKx with test results as #cmts at bottom
#Note - must use 'bash' shell for HEX to work at all, but complement option not
working in hex
#
echo "$0 - rename all files in directory Deleting LowBit (except LineFeed) &
HighBit characters"
dir="$1";
if [[ ! -d "$dir" ]]; then
echo "usage: renameOK directory "
echo " ==================="
echo " - arg1 must be a directory"
exit 1; fi
#
reply="n"
until [ "$reply" = "y" ]
do echo "enter to rename files ? y/n"
read reply
done
x=0; y=0
for dfn in $dir/*
do fn1=${dfn##*/}
fn2=$(echo $fn1 | tr -cd '\12\40-\176') #<-- OCTAL works, but HEX
preferred
# fn2=$(echo $fn1 | tr -cd \$'\x0A\x20-\x7E') #<-- HEX disabled, see
renameOKx to test
#Note - option 'c' of '-cd' COMPLEMENTS (deletes all characters not
specified)
# echo "Debug: fn1=$fn1 fn2=$fn2"
let x=x+1
if [[ $fn1 == $fn2 ]]; then continue; fi
mv -i "$dir/$fn1" $dir/$fn2
#==========================
let y=y+1
echo "file# $x $dir/$fn1 - renamed to: $dir/$fn2"
done
echo "total $x files, $y renamed deleting LowBit (except LineFeed) & HighBit
characters"
exit 0
#!/bin/bash
# renameOKx - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
# renameOKx - rename directory of filenames <-- delete chars in HEX, does NOT
work ???
# - Deleting all LowBit (except LineFeed) & HighBit characters
# renameOK <-- Alternate version specifies delete chars in OCTAL & does work
# renameOKx <-- This script specifies delete chars in HEX, but does NOT work -
WHY NOT ???
# --> see test input/output at bottom
#Note - must use 'bash' shell for HEX to work at all, but complement option not
working in hex
#
echo "$0 - rename all files in directory Deleting LowBit (except LineFeed) &
HighBit characters"
dir="$1";
if [[ ! -d "$dir" ]]; then
echo "usage: renameOKx directory "
echo " ==================="
echo " - arg1 must be a directory"
exit 1; fi
#
reply="n"
until [ "$reply" = "y" ]
do echo "enter to rename files ? y/n"
read reply
done
x=0; y=0
for dfn in $dir/*
do fn1=${dfn##*/}
# fn2=$(echo $fn1 | tr -cd '\12\40-\176') #<-- octal obsolete & stupid
fn2=$(echo $fn1 | tr -cd \$'\x0A\x20-\x7E') #<-- hex preferred, but has bugs
?
#Note - option 'c' of '-cd' COMPLEMENTS (deletes chars not specified)
# - does NOT work if chars specified in HEX, but OK if OCTAL - WHY diff
???
# echo "Debug: fn1=$fn1 fn2=$fn2"
let x=x+1
if [[ $fn1 == $fn2 ]]; then continue; fi
mv -i "$dir/$fn1" $dir/$fn2
#==========================
let y=y+1
echo "file# $x $dir/$fn1 - renamed to: $dir/$fn2"
done
echo "total $x files, $y renamed deleting LowBit (except LineFeed) & HighBit
characters"
exit 0
# renameOKx tmp1
# ==============
#
# Original filenames in directory tmp1
# -rw-r----- 1 uvadm apps 84335 Nov 5 08:09 Another.jpg
# -rw-r----- 1 uvadm apps 1500403 Nov 5 08:10 IMG_20170121_142512.jpg
# -rw-r----- 1 uvadm apps 48151 Nov 5 08:11 Mia - tomato% +head art.jpg
# -rw-r----- 1 uvadm apps 92384 Nov 5 09:11 My art: at^ _vsb |offices.jpg
#
# Resulting filenames after --> renameOKx tmp1
# -rw-r----- 1 uvadm apps 84335 Nov 5 09:14 Anotherjpg
# -rw-r----- 1 uvadm apps 1500403 Nov 5 09:14 IMG_20170121_142512jpg
# -rw-r----- 1 uvadm apps 92384 Nov 5 09:14 Mart:at^_vsbofficesjpg
# -rw-r----- 1 uvadm apps 48151 Nov 5 09:14 Miatomatoheadartjpg
#
# renameOK tmp1 <-- Alternate script specifies delete chars in Octal works OK
# ============= - why don't renameOKx HEX chars work ???