how do I feed a script conf file variables on the command line ?
Giorgos Keramidas
keramida at ceid.upatras.gr
Fri Nov 25 07:45:41 GMT 2005
On 2005-11-25 02:11, user <user at 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
More information about the freebsd-questions
mailing list