'Change the working directory in a shell.  Since this class is not used in the initial download stage,
no recipe step filtering is performed here and a None value is return for filtered_actions.  However,
the new dir value is returned since it is needed for later steps.'

def execute_step(self, tool_dependency, package_name, actions, action_dict, filtered_actions, env_file_builder, install_environment, work_dir, current_dir=None, initial_download=False):

    def dir_valid(test_dir):
        '\n                                                Make    sure    the    defined    directory    is    within    current_dir    or    work_dir.\n                                                '
        for valid_dir in [os.path.realpath(current_dir), os.path.realpath(work_dir)]:
            if (test_dir.startswith(valid_dir) and os.path.exists(test_dir)):
                return True
        return False
    target_dir = os.path.realpath(os.path.normpath(action_dict['directory']))
    if dir_valid(target_dir):
        dir = target_dir
    else:
        target_dir = os.path.realpath(os.path.normpath(os.path.join(current_dir, action_dict['directory'])))
        if dir_valid(target_dir):
            dir = target_dir
        else:
            log.debug('Invalid    or    nonexistent    directory    %s    specified,    ignoring    change_directory    action.', str(action_dict['directory']))
            dir = current_dir
    return (tool_dependency, None, dir)
