Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Nov 2005 09:44:23 +0200
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        user <user@dhp.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: how do I feed a script conf file variables on the command line ?
Message-ID:  <20051125074423.GB1567@flame.pc>
In-Reply-To: <Pine.LNX.4.21.0511250208420.8180-100000@shell.dhp.com>
References:  <Pine.LNX.4.21.0511250208420.8180-100000@shell.dhp.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2005-11-25 02:11, user <user@dhp.com> wrote:
> Ok, let's say I have a shell script named script.sh, and
> script.sh sucks in a file /etc/file.conf that contains nothing
> but variable declarations like:
>
> SETTING1=setting1
> SETTING2=setting2
>
> and so on.  Very simple.
>
> My question is, what if I want to feed the script a setting on
> the command line ?
>
> Normally I run the script:
>
> script.sh -x -v -e -r
>
> and it looks for /etc/file.conf and sucks in all the variables.
>
> But I want to:
>
> script.sh -x -v -e -r SETTING1='setting1'
>
> for some reason this is not working.  I am in the FreeBSD csh
> shell when I attempt this (FWIW).
>
> I just want to be able to quickly bypass the conf file, using a
> single command line.

Try env(1).

	env SETTING1='setting1' sh script.sh

This should work much better.  In fact, it's the same trick I use
in my local networking setup scripts.  Instead of hard-coding
everything in /etc/rc.conf, I have something like this:

    flame# cat -n /root/netstart-home.sh
         1  #
         2  # Set up network interfaces for my home network.
         3  #
         4
         5  export ifconfig_ath0="DHCP ssid "gker" \
         6      wepmode on weptxkey 1 wepkey '1:0xXXXXXXXXXXXXXXXXXXXXXXXXXX'"
         7  export defaultrouter="192.168.1.2"
         8
         9  #
        10  # Make sure the bge0 interface is brought down and then up again,
        11  # with the new IP address.
        12  #
        13  /etc/rc.d/netif stop bge0
        14  /etc/rc.d/netif stop ath0
        15  /etc/rc.d/netif start ath0

You can see around lines 5-7 that I'm setting stuff in the
environment, which will be picked up by the /etc/rc.d/netif
system script.

- Giorgos




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20051125074423.GB1567>