diff --git a/shell.py b/shell.py index 4ea1cc6..2f893c5 100644 --- a/shell.py +++ b/shell.py @@ -20,7 +20,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. # -# Ver. 0.1.0032 +# Ver. 0.1.0033 import types as _types @@ -193,6 +193,7 @@ conventionally called args or argv""" b = self.getBatch(ret[0]) if b: ret = b + ret + ret[0] = _re.sub(r'\A\$\((\w+)\)', r'\1', ret[0]) return ret # Default functions @@ -207,14 +208,15 @@ conventionally called args or argv""" def defineBatch(self, args): """Define a batch file.""" - if len(args) != 1: - raise ValueError('def takes only one argument') + if len(args) < 1: + raise ValueError('def takes at least one argument') ret = [] command = input(self.ps2) while command != 'end': ret.append(command) command = input(self.ps2) - self.registerBatch(args[0], ret) + for i in args: + self.registerBatch(i, ret) def batch(self, args): """Run commands in batch mode @@ -243,6 +245,8 @@ $>=0 - $>=n is the nth and later arguments""" newLine = newLine.replace(m.group(), ' '.join(args[num:])) else: newLine = newLine.replace(m.group(), args[int(n)]) + newLine = _re.sub(r'\A({0})'.format(args[0]), r'$(\1)', newLine) + #print(newLine) self.handleCommand(self.scanLine(newLine)) # Beyond this point are functions that are called within the main loop.