[mdlug] How to find file name length?
Raymond McLaughlin
driveray at ameritech.net
Thu Sep 27 02:20:29 EDT 2007
Paul wrote:
> Raymond McLaughlin <driveray at ameritech.net>, on Wed Sep 26, 2007 [06:51:55 PM] said:
>> Also did any one notice that the "echo "$(basename "{}" | wc -c" part
>> doesn't work as intended? Observe:
>>
>> echo filename.txt | wc -c
>> 13
>>
>> wc counts the trailing new line as a character, you need to use "echo -n"
>>
>> echo -n filename.txt | wc -c
>> 12
>>
>>
>> Ray
>
> Hi;
>
> Yeah, I noticed;) its called slop. You cant just shove a
> -n into my example without having to do something extra, since Im
> just using one echo, the -n wouldn't truncate the right newline,
> and you would just get a big blob of output. (the result length
> is calculated before echo gets involved.)
You are right, you can't just shove a -n into your example, but "echo
-n" still works, if you shove in a whole "echo -n $(...)"
Your example:
find -type f -exec bash -c 'echo "$(basename "{}" | wc -c) {}" '
adding echo -n makes it work, at least in my limited testing:
find -type f -exec bash -c 'echo "$(echo -n $(basename "{}") | wc -c) {}" '
Ray
More information about the mdlug
mailing list