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 />

echo "${1##$first}"<br />

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

#:docstring strtok:<br />

# Usage: strtok s1 s2<br />

#<br />

# Strtok considers the string s1 to consist of a sequence of zero or more<br />

# text tokens separated by spans of one or more characters from the<br />

# separator string s2. The first call (with a non-empty string s1<br />

# specified) echoes a string consisting of the first token on stdout. The<br />

# function keeps track of its position in the string s1 between separate<br />

# calls, so that subsequent calls made with the first argument an empty<br />

# string will work through the string imme<strong>di</strong>ately following that token. In<br />

# this way subsequent calls will work through the string s1 until no tokens<br />

# remain. The separator string s2 may be <strong>di</strong>fferent from call to call.<br />

# When no token remains in s1, an empty value is echoed on stdout.<br />

#:end docstring:<br />

###;;;autoload<br />

function strtok ()<br />

{<br />

:<br />

}<br />

#:docstring strtrunc:<br />

# Usage: strtrunc $n $s1 {$s2} {$...}<br />

#<br />

# Used by many functions like strncmp to truncate arguments for comparison.<br />

# Echoes the first n characters of each string s1 s2 ... on stdout.<br />

#:end docstring:<br />

###;;;autoload<br />

function strtrunc ()<br />

{<br />

n=$1 ; shift<br />

for z; do<br />

echo "${z:0:$n}"<br />

done<br />

}<br />

# provide string<br />

# string.bash ends here<br />

# ========================================================================== #<br />

# ==> Everything below here added by the document author.<br />

# ==> Suggested use of this script is to delete everything below here,<br />

# ==> and "source" this file into your own scripts.<br />

# strcat<br />

string0=one<br />

643

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

Saved successfully!

Ooh no, something went wrong!