在具有动态子代的上下文中,以编程方式迭代这些子代可能非常有用。这可以使用 list 函数实现,该函数返回动态子代数组。
script
       run('shares');
       projects = list();
       for (i = 0; i < projects.length; i++) {
               run('select ' + projects[i]);
               shares = list();
               for (j = 0; j < shares.length; j++) {
                       run('select ' + shares[j]);
                       printf("%s/%s %1.64g %1.64g\n", projects[i], shares[j],
                           get('space_data'), get('space_available'));
                       run('cd ..');
               }
               run('cd ..');
       }
            % ssh root@koi < space.aksh Password: admin/accounts 18432 266617007104 admin/exports 18432 266617007104 admin/primary 18432 266617007104 admin/traffic 18432 266617007104 admin/workflow 18432 266617007104 aleventhal/hw_eng 18432 266617007104 bcantrill/analytx 1073964032 266617007104 bgregg/dashbd 18432 266617007104 bgregg/filesys01 26112 107374156288 bpijewski/access_ctrl 18432 266617007104 ...
script
       run('shares');
       projects = list();
       printf('%-40s %-10s %-10s\n', 'SHARE', 'USED', 'AVAILABLE');
       for (i = 0; i < projects.length; i++) {
               run('select ' + projects[i]);
               shares = list();
               for (j = 0; j < shares.length; j++) {
                       run('select ' + shares[j]);
                       share = projects[i] + '/' + shares[j];
                       used = run('get space_data').split(/\s+/)[3];
                       avail = run('get space_available').split(/\s+/)[3];
                       printf('%-40s %-10s %-10s\n', share, used, avail);
                       run('cd ..');
               }
               run('cd ..');
       }
            % ssh root@koi < prettyspace.aksh Password: SHARE USED AVAILABLE admin/accounts 18K 248G admin/exports 18K 248G admin/primary 18K 248G admin/traffic 18K 248G admin/workflow 18K 248G aleventhal/hw_eng 18K 248G bcantrill/analytx 1.00G 248G bgregg/dashbd 18K 248G bgregg/filesys01 25.5K 100G bpijewski/access_ctrl 18K 248G ...
格式为:list ([depth, [filter]])。参数 depth 可指定为一个数字。depth 的数值越大,返回的信息越详细。参数 filter 采用 {<prop1>:<val1>, <prop2>:<val2> ...} 格式。如果指定 filter,则还必须指定 depth。
用法和输入行为:
list()-仅返回节点名称。
list(0)-返回节点属性和子节点名称。
list(0, {kiosk_mode: true})-如果 kiosk_mode 为 true,返回过滤后的列表,其中包含子节点的名称。
list(1)-返回节点的属性、子节点的名称和属性、孙节点的名称。
list(1, {kiosk_mode: true})-如果 kiosk_mode 为 true,返回过滤后的列表,其中包含的详细信息具体到 depth=1。
list(2)-返回节点的属性、子节点的名称和属性以及孙节点的 list(0) 输出。
list(2, {fullname:'Super*', kiosk_mode: true})-如果包含 Super 和 kiosk_mode 的 fullname 为 true,返回过滤后的列表,其中包含的详细信息具体到 depth=2。
标签 name 显示列表项(即,节点)的名称。标签 properties 显示列表项的属性。标签 children 显示列表项的静态子代。标签 list 显示列表项的动态子代。
script
        ("." to run)> dump(list(2));
        ("." to run)> .
        [{
            name: 'restuser',
            properties: {
                kiosk_screen: 'status/dashboard',
                kiosk_mode: false,
                roles: ['basic'],
                require_annotation: false,
                initial_password: 'DummyPassword',
                fullname: 'REST User',
                logname: 'restuser'
            },
            children: [{
                name: 'preferences',
                properties: {
                    advanced_analytics: false,
                    session_timeout: 15,
                    login_screen: 'status/dashboard',
                    locale: 'C'
                }
            }, {
                name: 'exceptions',
                list: [{
                    name: 'auth-000',
                    properties: {
                         allow_configure: false,
                         scope: 'alert'
                    }
                }, {
                    name: 'auth-001',
                    properties: {
                         allow_workgroup: false,
                         allow_domain: false,
                         name: '*',
                         scope: 'ad'
                    } 
                }]
            }]
        }]