1

I am still very new to shell since I have been using it with linux recently, and I tried to mess with a game called garrysmod and make a little script that will ask for information to run the server, its IP, playerslots, etc. Now I somewhat got this working, but I want to be able to save and load this to a config file. I figure out how to get it load from the config, but I want to be able to edit it from the command prompt when it asks you if you would like to edit it.

This is what I have so far as an example:

setup.sh

source config.cfg
echo "Servers current name is $name"
echo
echo "What would you like the name to be?"
read $name
read "The new name is $name"\

config.cfg

name='ServerName'
address=127.0.0.1
port=27015
map='ttt_mapnamehere.bsp'
playercap=32

Now it works after you change it, but I don't know how to get it to save to the .cfg file. The reason of this is because several .sh files will run in order as you go through the steps, and at the end the file one will pull data from the config file being the IP, port, map name, player count, etc. If someone can show me how to do this (examples as Im a visual learner) that would be great!

  • Ok, while this might sound like a duplicate of [this](http://stackoverflow.com/questions/5983558) or [that](http://stackoverflow.com/questions/16260165) question, there is no solution in either to help to **write** the config file, only to read it. You don't want to source, see [that](http://stackoverflow.com/questions/16260165) question. – martin Aug 15 '14 at 10:30
  • possible duplicate of [Bash: Update a variable within a file](http://stackoverflow.com/questions/25268688/bash-update-a-variable-within-a-file) – fedorqui Aug 15 '14 at 10:48

1 Answers1

0

Simply write it back:

...

printf "name='%s'\naddress='%s'\nport=%s\nmap='%s'\nplayercap=%s\n" \
    "$name" "$address" "$port" "$map" "$playercap" > config.cfg
konsolebox
  • 72,135
  • 12
  • 99
  • 105