From owner-freebsd-questions@FreeBSD.ORG Sun Aug 30 23:18:47 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7B98B106568F for ; Sun, 30 Aug 2009 23:18:47 +0000 (UTC) (envelope-from miklosovic.freebsd@gmail.com) Received: from mail-fx0-f210.google.com (mail-fx0-f210.google.com [209.85.220.210]) by mx1.freebsd.org (Postfix) with ESMTP id 060808FC12 for ; Sun, 30 Aug 2009 23:18:46 +0000 (UTC) Received: by fxm6 with SMTP id 6so2344989fxm.43 for ; Sun, 30 Aug 2009 16:18:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=EgI7z49B+USxpd27iz8klBDPCFPesKVXF6UJIwkW9mA=; b=d4B82t+KGWNsK40/ZzKdbVBL9AD/wwv6KvdKukBXHLrgWS2c/4SprM3RDJGkkabPCY mBAskbtBzEUl17q5Dm6NUicE8hy3hGZcex/x2K2lwvPurE1QJzJu5y+K2EweK4nebjHQ Jd0H5EKNnmJlmJ8jU32L4sOd5wFgS3YWpRS1s= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=TbmOAGEQEqHtCumOEIG4b02aHy7nehd8Ol8SKjhI3DWOBudGB67doeVur3gEWax+3u dh8gA1o/F+iTc+pAqA3+xx0rWvk/GGUrTSK9o74u6UPQUu5CHc/tziYcLb2W5d8Cxd1n 7r1y2gsofm0qbuVMBmDXq9ZHwPPNxSpEAQnTQ= MIME-Version: 1.0 Received: by 10.102.245.20 with SMTP id s20mr1791068muh.74.1251674326024; Sun, 30 Aug 2009 16:18:46 -0700 (PDT) In-Reply-To: References: Date: Mon, 31 Aug 2009 01:18:43 +0200 Message-ID: From: Stefan Miklosovic To: freebsd-questions@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: Re: shell command line argument + parsing function X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 30 Aug 2009 23:18:47 -0000 hehe :D easy as hell, one has to enclose argument of parse_cmdline into brackets :) parse_cmdline "$@" sorry for noise On Mon, Aug 31, 2009 at 1:07 AM, Stefan Miklosovic < miklosovic.freebsd@gmail.com> wrote: > hi, > > assuming I execute shell script like this > > $ ./script -c "hello world" > > I want to save "hello world" string to variable COMMENT in shell script. > > code: > > #!/bin/sh > > parse_cmdline() { > while [ $# -gt 0 ]; do > case "$1" in > -c) > shift > COMMENT="$1" > ;; > esac > shift > done > } > > parse_cmdline $* > > echo $COMMENT > > exit 0 > > but that only write out "hello". I tried to change $* to $@, nothing > changed. > > It is interesting, that if I dont put "while" loop into function > parse_cmdline, > and do echo $COMMENT, it writes "hello world". > > I WANT that function style. How to do it ? > > thank you >