From owner-freebsd-questions Wed May 14 13:10:38 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id NAA01579 for questions-outgoing; Wed, 14 May 1997 13:10:38 -0700 (PDT) Received: from iceberg.anchorage.net. (root@iceberg.anchorage.net [207.14.72.150]) by hub.freebsd.org (8.8.5/8.8.5) with SMTP id NAA01559 for ; Wed, 14 May 1997 13:10:34 -0700 (PDT) Received: from aak.anchorage.net (ai-129 [207.14.72.129]) by iceberg.anchorage.net. (8.6.11/8.7.3) with SMTP id LAA09002; Wed, 14 May 1997 11:07:20 -0800 Date: Wed, 14 May 1997 12:00:30 -0800 (AKDT) From: Steve Howe X-Sender: abc@aak.anchorage.net Reply-To: Steve Howe To: Zahemszky Gabor cc: FreeBSD questions , un_x@anchorage.net Subject: Re: parameter expansion In-Reply-To: <199705141303.PAA00546@CoDe.hu> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-questions@freebsd.org X-Loop: FreeBSD.org Precedence: bulk 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 ...