#!/bin/bash ### Imports ################################################################### source ScriptFunctions Import OptionParser ### Options ################################################################### helpOnNoArguments=yes scriptNotes="$scriptName processes a file replacing instances of variables marked with special indicators ('@%', '%@' by default) with the contents of equivalent environment variables." Add_Option_Entry "o" "open" "Opening mark." "@%" Add_Option_Entry "c" "close" "Closing mark." "%@" Add_Option_Entry "i" "identifier" "Add a prefix identifier in the form of '_' to the opening markup." Parse_Options "$@" ### Operation ################################################################# open=`Entry "open"` close=`Entry "close"` if Is_Entry "identifier" then open="${open}`Entry identifier`_" fi cat "$(Arg 1)" | python -c ' import os,sys,string op=sys.argv[1] cl=sys.argv[2] for line in sys.stdin.readlines(): while 1: op_index=line.find(op) if op_index == -1: break cl_index=line.find(cl) if cl_index == -1: break var = line[op_index + len(op):cl_index] try: val = os.environ[var] except: val = "" line = line.replace(op + var + cl, val) print line, ' "$open" "$close"