Thursday, October 30, 2008

Watch Soft Park Online

Advanced Scripts: A script that parses a file Debate

One of scripts. Tickets will go on making scripts, some introductory and more advanced. Today we will see how to make our scripts can set their variables from external files.

This is especially useful when we update our scripts on different machines and do not want to alter the configuration of each.
copy.sh

# / bin / bash
ruta_origen = / home / juanjo
destination_path = / mnt

function copy {$ cp-vr} ruta_origen $ destination_path With what if we change the script to your computer, maybe / home / junajo not exist. Let's do it right. Create a properties file, for example
copy.sh.properties
And in place: # File
copy.sh Properties property = value
    # source = / home / juanjo
  1. destination = / mnt
    Now in the file add the function copy.sh property: # / bin / bash function
    Property {
    if test-r $ 0.properties
  2. Then
  3. cat $ 0.properties take care!

0 comments:

Post a Comment