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.

function hash_set {<br />

eval "${Hash_config_varname_prefix}${1}_${2}=\"${3}\""<br />

}<br />

# Emulates: value=hash[key]<br />

#<br />

# Params:<br />

# 1 - hash<br />

# 2 - key<br />

# 3 - value (name of global variable to set)<br />

function hash_get_into {<br />

eval "$3=\"\$${Hash_config_varname_prefix}${1}_${2}\""<br />

}<br />

# Emulates: echo hash[key]<br />

#<br />

# Params:<br />

# 1 - hash<br />

# 2 - key<br />

# 3 - echo params (like -n, for example)<br />

function hash_echo {<br />

eval "echo $3 \"\$${Hash_config_varname_prefix}${1}_${2}\""<br />

}<br />

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

# Emulates: hash1[key1]=hash2[key2]<br />

#<br />

# Params:<br />

# 1 - hash1<br />

# 2 - key1<br />

# 3 - hash2<br />

# 4 - key2<br />

function hash_copy {<br />

eval "${Hash_config_varname_prefix}${1}_${2}=\"\$${Hash_config_varname_prefix}${3}_${4}\""<br />

}<br />

# Emulates: hash[keyN-1]=hash[key2]=...hash[key1]<br />

#<br />

# Copies first key to rest of keys.<br />

#<br />

# Params:<br />

# 1 - hash1<br />

# 2 - key1<br />

# 3 - key2<br />

# . . .<br />

# N - keyN<br />

function hash_dup {<br />

local hashName="$1" keyName="$2"<br />

shift 2<br />

until [ ${#} -le 0 ]; do<br />

657

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

Saved successfully!

Ooh no, something went wrong!