Re: Shell scripts: determining filename length

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wednesday 07 September 2005 10:06, Brian D. McGrew 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?
>

Take a look at 'man bash', specifically the section on 'parameter 
expansion'.  You'll see a few entries associated with length that 
might be useful.  For example: 

======== strlength.sh ========
#!/bin/bash

echo "The string has "${#1}" characters"
echo "First 10 characters: "${1:0:10}
echo "Last 3 characters: "${1:${#1}-3:3}
===============================

$ ./strlength.sh 123456789012345.txt

The string has 19 characters
First 10 characters: 1234567890
Last 3 characters: txt


Regards, Mike Klinke

-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux