11.04.2013 Views

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

{<br />

}<br />

[ "$1" = "$2" ] && return 0<br />

[ "${1}" ’ /dev/null && return -1<br />

return 1<br />

Appen<strong>di</strong>ce A. Script aggiuntivi<br />

#:docstring strncmp:<br />

# Usage: strncmp $s1 $s2 $n<br />

#<br />

# Like strcmp, but makes the comparison by examining a maximum of n<br />

# characters (n less than or equal to zero yields equality).<br />

#:end docstring:<br />

###;;;autoload<br />

function strncmp ()<br />

{<br />

if [ -z "${3}" -o "${3}" -le "0" ]; then<br />

return 0<br />

fi<br />

}<br />

if [ ${3} -ge ${#1} -a ${3} -ge ${#2} ]; then<br />

strcmp "$1" "$2"<br />

return $?<br />

else<br />

s1=${1:0:$3}<br />

s2=${2:0:$3}<br />

strcmp $s1 $s2<br />

return $?<br />

fi<br />

#:docstring strlen:<br />

# Usage: strlen s<br />

#<br />

# Strlen returns the number of characters in string literal s.<br />

#:end docstring:<br />

###;;;autoload<br />

function strlen ()<br />

{<br />

eval echo "\${#${1}}"<br />

# ==> Returns the length of the value of the variable<br />

# ==> whose name is passed as an argument.<br />

}<br />

#:docstring strspn:<br />

# Usage: strspn $s1 $s2<br />

#<br />

# Strspn returns the length of the maximum initial segment of string s1,<br />

# which consists entirely of characters from string s2.<br />

#:end docstring:<br />

641

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!