Date: Wed, 14 May 1997 12:00:30 -0800 (AKDT) From: Steve Howe <un_x@anchorage.net> To: Zahemszky Gabor <zgabor@CoDe.hu> Cc: FreeBSD questions <freebsd-questions@freebsd.org>, un_x@anchorage.net Subject: Re: parameter expansion Message-ID: <Pine.BSF.3.95q.970514114558.15079A-100000@aak.anchorage.net> In-Reply-To: <199705141303.PAA00546@CoDe.hu>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 14 May 1997, Zahemszky Gabor wrote: > > t=file.gz.tar.gz > > echo ${t%.gz} > > echo ${t%%.gz} > > > > i've been trying to figure out the difference between > > using 1 or 2 "%" in my expansions, but haven't had any luck! > > whether 1 or 2, i can't see any difference. > > ------------------------------------------------------------------------- > Well, it has a difference, if you use joker characters that match > more than one character (of course, there is only one: *): you are right. it only makes a difference if you use "*", which will match the longest suffix possible. > $ echo $MAIL # SUFFIX > /var/mail/zgabor > $ echo ${MAIL%/*} # matches only "/zgabor" > /var/mail > $ echo ${MAIL%%/*} # matches "/var/mail/zgabor" > > $ > > or another one: # PREFIX > $ echo ${MAIL#*/} > var/mail/zgabor # matches "/" > $ echo ${MAIL##*/} > zgabor # matches "/var/mail/" > $ > > Bye, Gabor hey - thanks! > PS: is it works in your sh? On my 2.1.5 from sh, I got only: > Syntax error: Bad substitution yes - my example above works w/2.2.1. why shouldn't it? :) > -- #!/bin/ksh Z='21N16I25C25E30, 40M30E33E25T15U!' ;IFS=' ABCDEFGHIJKLMNOPQRSTUVWXYZ '; set $Z;for i { [[ $i = ? ]]&&print $i&&break;[[ $i = ??? ]]&&j=$i&&i=${i%?}; typeset -i40 i=8#$i;print -n ${i#???};[[ "$j" = ??? ]]&&print -n "${j#??} "&& j=;typeset +i i;};IFS=' 0123456789 ';set $Z;X=;for i { [[ $i = , ]]&&i=2; [[ $i = ?? ]]||typeset -l i;X="$X $i";typeset +l i;};print "$X" i tried this thing with sh - but only got errors :( (i was a little scared it would do something evil!) i don't have ksh ...
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.95q.970514114558.15079A-100000>