From owner-freebsd-questions@FreeBSD.ORG Wed Jun 2 10:10:15 2010 Return-Path: Delivered-To: questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 74A831065674 for ; Wed, 2 Jun 2010 10:10:15 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx02.qsc.de (mx02.qsc.de [213.148.130.14]) by mx1.freebsd.org (Postfix) with ESMTP id 36EDA8FC12 for ; Wed, 2 Jun 2010 10:10:14 +0000 (UTC) Received: from r55.edvax.de (port-92-195-249-33.dynamic.qsc.de [92.195.249.33]) by mx02.qsc.de (Postfix) with ESMTP id B0DB61DAE8; Wed, 2 Jun 2010 12:10:13 +0200 (CEST) Received: from r55.edvax.de (localhost [127.0.0.1]) by r55.edvax.de (8.14.2/8.14.2) with SMTP id o52AACcF001503; Wed, 2 Jun 2010 12:10:13 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Wed, 2 Jun 2010 12:10:12 +0200 From: Polytropon To: Aiza Message-Id: <20100602121012.38e91934.freebsd@edvax.de> In-Reply-To: <4C06131A.6010107@comclark.com> References: <4C06131A.6010107@comclark.com> Organization: EDVAX X-Mailer: Sylpheed 2.4.7 (GTK+ 2.12.1; i386-portbld-freebsd7.0) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: "questions@freebsd.org" Subject: Re: command to strip suffix in .sh script X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Polytropon List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Jun 2010 10:10:15 -0000 On Wed, 02 Jun 2010 16:15:22 +0800, Aiza wrote: > I have this code > > archive_name=`echo -n "${fromarchive}" | tr -c '[:alnum:]' _` > > ` is the key under Esc key and ' key is next to enter key. > > fromarchive value is archivename-201006021514.34.tar.gz > > I want to strip the suffix -201006021514.34.tar.gz from the archivename. > > The archivename can be upper and lower case letters interspersed with _ > > > Do I have syntax problem with the code? I get no error on it. > > Do I have the tr command coded correctly? > > Or should I be using something else instead of tr command? Maybe "cut" can help: % echo 'archivename-201006021514.34.tar.gz' | cut -d '-' -f 1 archivename Cutting -f 2 will give you the remaining component. % echo 'archivename-201006021514.34.tar.gz' | cut -d '-' -f 2 201006021514.34.tar.gz To cut off the suffix (.tar.gz), consider using "basename". -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...