Changeset 12024


Ignore:
Timestamp:
2008-07-30T22:35:22+02:00 (10 years ago)
Author:
nbd
Message:

functions.sh: add a function for removing an item from a list in a shell variable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/package/base-files/files/etc/functions.sh

    r10389 r12024  
    2323         
    2424        eval "export ${NO_EXPORT:+-n} -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\"" 
     25} 
     26 
     27list_remove() { 
     28        local var="$1" 
     29        local remove="$2" 
     30        local val 
     31 
     32        eval "val=\" \${$var} \"" 
     33        val1="${val%% $remove *}" 
     34        [ "$val1" = "$val" ] && return 
     35        val2="${val##* $remove }" 
     36        [ "$val2" = "$val" ] && return 
     37        val="${val1## } ${val2%% }" 
     38        eval "export ${NO_EXPORT:+-n} -- \"$var=\$val\"" 
    2539} 
    2640 
Note: See TracChangeset for help on using the changeset viewer.