Shell scripts: determining filename length
inode0
inode0 at gmail.com
Wed Sep 7 15:41:05 UTC 2005
On 9/7/05, Brian D. McGrew <brian at visionpro.com> wrote:
> Good morning.
>
> I'm working on some shell scripts that process directories full of times
> shared by Samba and used by Windows people. We all know that Windows
> people have a habit of really, really, really, long filenames.
>
> In a shell script, inside a `for f in *` loop, how can I go about
> finding how long a filename is ... And then truncate the name, keeping
> the three letter extension, to less than 64 characters?
In bash you can do something like the following
for f in *; do
if [ ${#f} -ge 64 ]; then
munging filename left as exercise but look at
${parameter:offset:length} in the bash man
page for a handy shell way to snip a variable
fi
done
John
More information about the redhat-list
mailing list