From owner-freebsd-questions@FreeBSD.ORG Sun Aug 30 23:07:38 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 312C4106566C for ; Sun, 30 Aug 2009 23:07:38 +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 B63528FC19 for ; Sun, 30 Aug 2009 23:07:37 +0000 (UTC) Received: by fxm6 with SMTP id 6so2342777fxm.43 for ; Sun, 30 Aug 2009 16:07:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=jJVyKkdbyN+GMZbMPuqCcvA2qKvUjiSAgaweHJSq6bc=; b=Yv1MCw24Bpad0XWVp35uLzlglERGVeRH6NYpx8XvcQcq8gXe/k9Ud6N6kBGRuUk08d lkqAeWDn+KIziYD64PPefw4SM9i9ce/Zb58hn98/gWr51hXUAU7h4Jk7x72In9KT2xIG iziAHjSkWIRjlR6TaKNATdSWQ9JFpYM5FiwNo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=PmNOI7QmQ+q82g4mvD5pKtfRKlHbKMl5T3uIzBS6wCVrz2AADFSoxglIg6mLf5i91+ QnUc3MOCtTbDJpsAKIZSFS2R+4oAA1y9AKHdXMjOO4ELKpsMOeQiGm45I4ALb6/3bqZa SEI7BHOlHBxTsAk9aA5g7wei/BmHeWal4cza4= MIME-Version: 1.0 Received: by 10.103.127.28 with SMTP id e28mr1766377mun.120.1251673656596; Sun, 30 Aug 2009 16:07:36 -0700 (PDT) Date: Mon, 31 Aug 2009 01:07:36 +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: 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:07:38 -0000 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