From owner-freebsd-questions@FreeBSD.ORG Wed Apr 9 19:28:15 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9628A4D3 for ; Wed, 9 Apr 2014 19:28:15 +0000 (UTC) Received: from nightmare.dreamchaser.org (nightmare.dreamchaser.org [12.32.44.142]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 645CD14AC for ; Wed, 9 Apr 2014 19:28:15 +0000 (UTC) Received: from breakaway.dreamchaser.org (breakaway.dreamchaser.org. [12.32.36.73]) by nightmare.dreamchaser.org (8.13.6/8.13.6) with ESMTP id s39JS7OU006393 for ; Wed, 9 Apr 2014 13:28:07 -0600 (MDT) (envelope-from garya@dreamchaser.org) Message-ID: <53459F47.6080407@dreamchaser.org> Date: Wed, 09 Apr 2014 13:28:07 -0600 From: Gary Aitken User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:17.0) Gecko/20130730 Thunderbird/17.0.7 MIME-Version: 1.0 To: FreeBSD Mailing List Subject: blindly passing on shell flags ($- )? X-Enigmail-Version: 1.5.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0.2 (nightmare.dreamchaser.org [12.32.36.65]); Wed, 09 Apr 2014 13:28:07 -0600 (MDT) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Apr 2014 19:28:15 -0000 As I read the man page for sh and bash, the variable $- is supposed to represent the flags passed to the script. However, whenever I look at it it is empty. Reading between the lines, it appears one may have to call getopts so the shell knows what the flags are, but that doesn't seem to change what's available in $-. Fundamentally, I want to add an arg (not a flag) and pass the whole shebang on to another script. Seems like this should be trivial but I can't get it to work. The flags seem to be treated as a normal arg. The only way I seem to be able to get what I want is to interpret all the flags in the first script and pass them explicitly to the second, which is what I'm trying to avoid. foo: #!/bin/sh echo foo here echo flags $- echo args $1 $2 bar $- INSERTED $1 $2 getopts ah flag bar $- INSERTED $1 $2 bar: #!/bin/sh echo bar here echo flags $- echo args $1 $2 $3 $foo -a abc foo here flags args -a abc bar here flags args INSERTED -a abc bar here flags args INSERTED -a abc What am I missing? Thanks, Gary