Script snippets

I recently needed to trim the last N characters from a string in shell. I wrote this little function to handle it.
This requires a newer distro that has updated coreutils that includes the 'fold' command (Feb 2010).

#!/bin/bash  
function trimChars() {  
    if [ $2 ]; then  
        TRIM_LAST=$2  
    elif ! [ $2 …

Continue reading »