BASH
Configurare email
Configurare software
Hardware
Linux
Linux Mint
Pentru tonti
Securitate
VMWARE
Windows
bash :: functie bash pentru prelucrarea variabilelor multiple intoarse de o functie
CAMSCAPE SERVICES Cristian M. |
Title | Functie bash pentru prelucrarea variabilelor multiple intoarse de o functie |
Tags | bash, variabile multiple | |
Desc. | Functie bash pentru prelucrarea variabilelor multiple intoarse de o functie | |
Code | KBSH0009 v1.0 | |
Date | 2 octombrie 2012 |
var1,var2,var3,var4
Unde "," este separatorul dorit.
Functia de mai jos extrage parametrul dorit din stringul returnat de o alta functie.
function GetResultById { # Function to parse a string composed of several parts. # Will return the nth part. # Usefull to break apart multiple variables returned by a function. # # Usage: GetResultById "aaa,bbbb,dddd,223" 2 ',' will return bbbb # # Param: # - string containing all the parts, in the form PART1,PART2,... # - number of desired parameter # - separator (, in the example). Defaults to MULTIPLE_SEP variable # that can be set somewhere else # # Return: # - desired part # # Copyright CAMSCAPE SERVICES GPLv2 # http://www.camscape.ro # if [ "$3" != "" ]; then SEP=$3 else SEP=$MULTIPLE_SEP fi echo `echo $1 | cut --delimiter="$SEP" -f $2` }