Commits

Patrick Mézard committed 095d879

Implement $0

Comments (0)

Files changed (4)

         return env        
         
     def __getitem__(self, key):
-        if key in ('@', '*', '-', '$', '0'):
+        if key in ('@', '*', '-', '$'):
             raise NotImplementedError('%s is not implemented' % repr(key))
         return self._env[key]
         
         map(add_redir, ios)
         return redirs
             
-    def execute_script(self, script=None, ast=None, sourced=False):
+    def execute_script(self, script=None, ast=None, sourced=False,
+                       scriptpath=None):
         """If script is not None, parse the input. Otherwise takes the supplied
         AST. Then execute the AST.
         Return the script exit status.
         """
         try:
+            if scriptpath is not None:
+                self._env['0'] = os.path.abspath(scriptpath)
+
             if script is not None:
                 debug_parsing = ('debug-parsing' in self._debugflags)    
                 cmds, script = pyshyacc.parse(script, True, debug_parsing)
                     pyshyacc.print_commands(cmds, self._logfile)
                     self._logfile.flush()
             else:
-                cmds, script = ast, ''
+                cmds, script = ast, ''                
                 
             status = 0
             for cmd in cmds:
         return 0
 
     ast = None
+    command_file = None
     if options.command_string:
         input = cmdargs[0]
         if not options.ast:
             # Export given environment in shell object
             for k,v in env.iteritems():
                 ip.get_env().export(k,v)
-            return ip.execute_script(input, ast)
+            return ip.execute_script(input, ast, scriptpath=command_file)
         finally:
             ip.close()
     finally:

tests/test-positional

 }
 
 echo % '*' without field splitting
-testecho2 a b
+testecho2 a b
+
+echo '% test $0'
+echo $0 | sed 's/.*test-positional/test-positional/'
+echo `echo $0` | sed 's/.*test-positional/test-positional/'

tests/test-positional.out

 bbar
 % * without field splitting
 fooa b bar
+% test $0
+test-positional
+test-positional