Index: /trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli.pm
===================================================================
--- /trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli.pm	(revision 2463)
+++ /trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli.pm	(revision 2464)
@@ -181,4 +181,5 @@
         },
     }) if ($self->base->can('find_expired_users'));
+
     $self->add_func('expires', {
         help => 'expires [delay] - list account expiring before delay (default is 1 month)',
@@ -191,5 +192,8 @@
         },
     }) if ($self->base->can('find_next_expire_users'));
-    $self->add_func('select', {
+
+    $self->add_func(
+        'select',
+        {
             help => 'select object_type - select objects to perform action on it',
             completion => sub {
@@ -231,5 +235,6 @@
                 )->cli();
             },
-        });
+        }
+    );
 
 =head2 testpass
Index: /trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli/Base.pm
===================================================================
--- /trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli/Base.pm	(revision 2463)
+++ /trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli/Base.pm	(revision 2464)
@@ -156,6 +156,14 @@
 =cut
 
-    $self->add_func('quit', {
-            code => sub { $self->print("\n"); exit(0) }, });
+    $self->add_func(
+        'quit', 
+        {
+            code => sub {
+                $self->print("\n");
+                $self->_exit();
+                exit(0) 
+            },
+        }
+    );
 
 =head3 exit
@@ -165,6 +173,23 @@
 =cut
 
-    $self->add_func('exit', {
-            code => sub { return "EXIT" }, });
+    $self->add_func(
+        'exit',
+        {
+            code => sub { return "EXIT" },
+        }
+    );
+
+=head3 top
+
+Exit from any selection context
+
+=cut
+
+    $self->add_func(
+        'top',
+        {
+            code => sub { return "TOP" },
+        }
+    );
 
 =head3 !
@@ -723,6 +748,14 @@
     $self->Context->ReadHistory();
     $self->cli();
-    if (! $self->Context->WriteHistory() ) {
-        warn "Cannot write history:  $!\n";
+    $self->_exit();
+}
+
+sub _exit {
+    my ( $self ) = @_;
+ 
+    if ( -t ) {
+        if (! $self->Context->WriteHistory() ) {
+            warn "Cannot write history:  $!\n";
+        }
     }
     $self->Context->WritePreferences();
@@ -741,16 +774,18 @@
 
     while (1) {
-        $term->Attribs->{completion_function} = sub {
-            my ($Op, $Shell, @args) = $self->_parse_cmd_line(substr($_[1], 0, $_[2]));
-            $Op ||= '';
-            my $attribs = $self->Context->Term->Attribs;
-            if ($Op eq '>') {
-                $term->completion_matches($Shell, $attribs->{'filename_completion_function'});
-            } elsif ($Op eq '|') {
-                $term->completion_matches($Shell, $attribs->{'filename_completion_function'});
-            } else  {
-                $self->complete($_[0], @args);
-            }
-        };
+        if ( -t ) {
+            $term->Attribs->{completion_function} = sub {
+                my ($Op, $Shell, @args) = $self->_parse_cmd_line(substr($_[1], 0, $_[2]));
+                $Op ||= '';
+                my $attribs = $self->Context->Term->Attribs;
+                if ($Op eq '>') {
+                    $term->completion_matches($Shell, $attribs->{'filename_completion_function'});
+                } elsif ($Op eq '|') {
+                    $term->completion_matches($Shell, $attribs->{'filename_completion_function'});
+                } else  {
+                    $self->complete($_[0], @args);
+                }
+            };
+        }
         defined (my $line = $term->readline($self->prompt)) or do {
             $self->print("\n");
@@ -771,5 +806,16 @@
         }
         $self->rollback if (!$self->Context->TransMode);
-        if ($res && $res eq 'EXIT') { $self->print("\n"); return }
+        if ($res) {
+            if ( $res eq 'EXIT' ) {
+                $self->print("\n");
+                return
+            } elsif ( $res eq 'TOP' ) {
+                if ( $self->isa('LATMOS::Accounts::Cli::Object') ) {
+                    return 'TOP'
+                } else {
+                    $self->print("\n");
+                }
+            }
+        }
     }
 }
@@ -788,4 +834,5 @@
 sub prompt {
     my ($self) = @_;
+    if (! -t ) { return '> ' }
     my $pr = $self->promptPrefix;
     return sprintf(
