core/builtins/fshell.cif
changeset 0 7f656887cf89
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 # fshell.cif
       
     2 # 
       
     3 # Copyright (c) 2010 Accenture. All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of the "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 # 
       
     9 # Initial Contributors:
       
    10 # Accenture - Initial contribution
       
    11 #
       
    12 
       
    13 ==name fshell
       
    14 
       
    15 ==short-description
       
    16 
       
    17 A UNIX-like shell for Symbian OS.
       
    18 
       
    19 ==long-description
       
    20 
       
    21 =head2 Introduction
       
    22 
       
    23 F<fshell> is a console based executable for Symbian OS that behaves somewhat like typical UNIX shells (e.g. Bash, http://www.gnu.org/software/bash/ ). It can be used via a remote console implementation on hardware that doesn't have a full keyboard, giving an experience similar to telnet. F<fshell> contains a set of built-in commands and is also able to launch arbitrary Symbian OS executables. This document describes how to install F<fshell>, how to use its built-in commands and how to use the set of external commands that are also provided.
       
    24 
       
    25 =head2 Getting Started
       
    26 
       
    27 See L<Getting Started|getting_started> for a description of how to get console based tools like F<fshell> up and running on the platform you are using. Alternatively, if you would like to configure things yourself, see L<Console Options|console_options> for a description of the technology that's available for hosting consoles.
       
    28 
       
    29 F<fshell> is more like a UNIX shell than a DOS one, so it supports commands like C<cd Z:\>, C<ls>, C<mkdir> and C<rm>. It does also support the DOS-style equivalents C<z:> C<dir>, C<md>, and C<del> via internal fshell aliases. However, you still can't execute eshell *.bat files directly, although you can launch eshell from within fshell by typing 'eshell' so it is possible to run them indirectly if you need to. In practice, many simple bat files can run as fshell scripts due to fshell providing broadly-compatible commands.
       
    30 
       
    31 =head2 General fshell Functionality
       
    32 
       
    33 =over 5
       
    34 
       
    35 =item * Tab Completion
       
    36 
       
    37 At any point through entering a command, pressing the C<tab> key will cause F<fshell> to attempt to complete the part of the line currently being entered. Completion is performed on command names, directory and file names, and environment variables. If a command has been typed, and that command uses a L<CIF file|cif_syntax>, completion will additionally be performed on option names. Where the completion choice is ambiguous, a list of choices will be displayed above the line being edited. DOS-style F8 line completion is also supported, this looks in the command history for the first command that matches what has been typed so far. Pressing F8 repeatedly cycles through all the matching commands. For VT100 compatibility (F8 technically only became supported in VT220) F4 has the same effect.
       
    38 
       
    39 For example:
       
    40 
       
    41   Input:   c:\>under<TAB>
       
    42   Outputs: c:\>undertaker
       
    43 
       
    44   Input:   c:\>kill --<TAB>
       
    45   Outputs: c:\>kill --
       
    46            --reason  --terminate --panic --thread --match --all
       
    47 
       
    48   Input:   c:\>ls $P<TAB>
       
    49   Outputs: c:\>ls $PWD
       
    50 
       
    51 =item * Command History
       
    52 
       
    53 The 'up arrow' and 'down arrow' keys can be used to review previously entered commands. The commands entered in a particular session are persisted to disk when fshell is idle or when it is exited.
       
    54 
       
    55 =item * Standard Input / Output
       
    56 
       
    57 F<fshell> supports the notion of standard input / ouput. Each command has access to the following IO handles:
       
    58 
       
    59 =over 5
       
    60 
       
    61 =item * STDIN
       
    62 
       
    63 By default, keyboard input.
       
    64 
       
    65 =item * STDOUT
       
    66 
       
    67 By default, the console screen.
       
    68 
       
    69 =item * STDERR
       
    70 
       
    71 By default, the console screen.
       
    72 
       
    73 =back
       
    74 
       
    75 =item * Console Sharing
       
    76 
       
    77 F<fshell> arranges for all commands (including external ones run in separate processes) to share its console. This may not seem like a big deal as it's the behaviour you'd expect from using UNIX or DOS, but Symbian OS's default console implementation (F<econs.dll>) and shell implementation (F<eshell.exe>) run external commands in a separate console windows, making it difficult to see any output they may produce because their windows disappear when the command finishes.
       
    78 
       
    79 With the right configuration tweaks, fshell is capable of 'hooking up' existing CConsoleBase-based command line tools to share fshell's console. In other words fshell can transparently support running legacy command line tools as if they were native fshell tools. The same support is available for PIPS-based tools.
       
    80 
       
    81 =item * Pipelines
       
    82 
       
    83 The output of one command to be sent as input to another command. For example:
       
    84 
       
    85   cat text.txt | match *hello*
       
    86 
       
    87 This command-line causes the C<cat> command to print the contents of the file C<text.txt>. This output is directed into the L<match|match> command, which filters out any lines that don't contain the text C<hello>.
       
    88 
       
    89 =item * Redirection
       
    90 
       
    91 The output of commands can be redirected to files. For example:
       
    92 
       
    93   ls > ls.txt
       
    94 
       
    95 This causes the output of a directory listing (produced by the C<ls> command) to be redirected to the file C<ls.txt> in the current directory, replacing its current contents. The following command...
       
    96 
       
    97   ls >> ls.txt
       
    98 
       
    99 ...causes the directory listing to be appended to the current contents of F<ls.txt>.
       
   100 
       
   101 So far, all the examples have shown how C<STDOUT> can be redirected. It is however also possible to redirect C<STDERR>. For example...
       
   102 
       
   103   ls 2> stderr.txt > stdout.txt
       
   104 
       
   105 ...redirects C<STDERR> to the file F<stderr.txt> and C<STDOUT> to the file F<stdout.txt>. It is also possible to redirect C<STDERR> to C<STDOUT> (and vice versa), for example:
       
   106 
       
   107   ls 2>&1 > stderr_and_stdout.txt
       
   108 
       
   109 Lastly, it is also possible to redirect C<STDIN> to be read from a file rather than from the keyboard. For example...
       
   110 
       
   111   match *hello* < text.txt
       
   112 
       
   113 ...is equivalent to the first example but avoids using the C<cat> command.
       
   114 
       
   115 =item * Job Control
       
   116 
       
   117 Each command line is treated as a separate job within F<fshell>. Ordinarily, when F<fshell> is executing a job, any characters you enter using the keyboard are directed to the job. The presence of a 'C<&>' character at the end a of command line causes it to be run in the background. While such a job is running, F<fshell> will allow you to create and run other command lines. Whilst a job is running in the background, it will not receive any keyboard input.
       
   118 
       
   119 The following key combinations are intercepted by F<fshell>:
       
   120 
       
   121 =over 5
       
   122 
       
   123 =item * Ctrl-C
       
   124 
       
   125 Causes the foreground job to be terminated.
       
   126 
       
   127 =item * Ctrl-Z
       
   128 
       
   129 Causes the foreground job to be stopped (in the case of pre-platform security versions of Symbian OS) or sent to the background whilst still running (in the case of platform security versions of Symbian OS).
       
   130 
       
   131 =back
       
   132 
       
   133 See also the commands L<fg|fg>, L<bg|bg> and L<jobs|jobs>.
       
   134 
       
   135 =item * Conditional Execution
       
   136 
       
   137 Commands can conditionally execute using the logical 'and' operator C<&&>, the logical 'or' operator C<||> or the (somewhat strange) 'andor' operator C<&|>. For example...
       
   138 
       
   139   command_1 && command_2
       
   140 
       
   141 ...C<command_2> is only run if C<command_1> ran successfully (i.e. returned KErrNone). Or...
       
   142 
       
   143   command_1 || command_2
       
   144 
       
   145 ...C<command_2> is only run if C<command_1> did not run sucessfully (i.e. returned something other than KErrNone).
       
   146 
       
   147 The 'andor' operator is effectively an alternative for proper block support. It allows a script to contain conditional elements and then execute a block of commands regardless of whether previous ones have returned an error. This might sound like a strange thing to want to do, but it can be useful. For example...
       
   148 
       
   149   exist some_dir || do_something &| do_something_else
       
   150 
       
   151 In this example, "do_something" is only executed if "some_dir" does not already exist. However, if "do_something" is run, then "do_something_else" is also guaranteed to also run.
       
   152 
       
   153 =item * Environment variables
       
   154 
       
   155 Environment variables can be defined (and undefined) using the L<export|export> command. Once defined, variables can be used in fshell command lines (or scripts) by prefixing them with a C<$> sign as follows:
       
   156 
       
   157   c:\>export MYVAL 'some value'
       
   158   c:\>echo $MYVAL
       
   159   some value
       
   160 
       
   161 Fshell defines some variables at all times. C<PWD> is set to the current directory, and C<?> is set to the return code of the last command that ran. For example:
       
   162 
       
   163   c:\somewhere\>echo "Current dir is: $PWD"
       
   164   Current dir is: c:\somewhere\
       
   165   c:\somewhere\>error -3
       
   166   Error: Command "error" failed : KErrCancel (-3)
       
   167   c:\somewhere\>echo "Last command returned $?"
       
   168   Last command returned -3
       
   169 
       
   170 See the section on scripting for some further uses of environment variables. 
       
   171 
       
   172 =item * Escaping and Quoting
       
   173 
       
   174 F<fshell> treats the value of the variable C<ESCAPE> (which defaults to C<^>) as the beginning of an escape sequence. One or more characters following an escape are ignored by F<fshell's> usual string processing. The DOS-style '^' escape is used in preference for the more usual unix '\', because backslash is used as the path separator, and being forced to write C<cat C:\\dir\\file.txt> is considered more inconvenient. It is not recommended to change the escape character, particularly not to '\'.
       
   175 
       
   176 For example, to get list the contents of a directory whose name contains a space character:
       
   177 
       
   178   c:\>ls test^ dir
       
   179   test.txt
       
   180 
       
   181 The following escape sequences have special meanings:
       
   182 
       
   183   ^a          (bell)
       
   184   ^b          (back space)
       
   185   ^f          (form feed)
       
   186   ^n          (new line)
       
   187   ^r          (carriage return)
       
   188   ^t          (horizontal tab)
       
   189   ^v          (vertical tab)
       
   190   ^xnn        (numeric escape where 'n' is a hex digit)
       
   191   ^Xnn        (same as ^x)
       
   192   ^unnnn      (numeric escape for a UTF-16 character, where nnnn is a sequence of 4 hex digits)
       
   193   ^Unnnnnnnn  (same as ^u but for a UTF-32 character)
       
   194   ^^          (to represent the escape character itself.
       
   195                if $ESCAPE was a backslash, the sequence would be \\ etc.)
       
   196 
       
   197 For example:
       
   198 
       
   199   c:\>echo hello^r^x0aworld
       
   200   hello
       
   201   world
       
   202 
       
   203 Note, the hex value 0x0a corresponds to a new line character, which could have been represented by C<^n>.
       
   204 
       
   205 F<fshell> also supports use of single and double quotes around strings. With single quotes environment variables are not expanded and the only supported escape sequence is C<^'> to produce a literal single quote character. With double quotes, environment variables B<are> expanded and all the above escape sequences are supported. For example:
       
   206 
       
   207   c:\>export TEST "hello world"
       
   208   c:\>echo '^'$TEST^' will not be expanded'
       
   209   '$TEST' will not be expanded
       
   210   c:\>echo "TEST contains:^r^n$TEST"
       
   211   TEST contains:
       
   212   hello world
       
   213 
       
   214 =item * PIPS Integration
       
   215 
       
   216 If F<fshell> detects that it is launching a PIPS based executable (because it has a UID2 of 0x20004c45, the UID used by the makmake target C<stdexe>), it takes steps to ensure that F<fshell's> native implementations of pipes and environment variables are mapped onto those provided by PIPS. This is done using a helper executable named F<pipsrun.exe> that is responsible for providing the necessary translations. The end result is that the executables that use PIPS can share F<fshell's> console, take part in pipelines and also inherit environment variables.
       
   217 
       
   218 =back
       
   219 
       
   220 =head2 Commands
       
   221 
       
   222 All commands support the C<-h> (or C<--help>) option, which causes them to display text describing what they do and the syntax they support.
       
   223 
       
   224 A list of all the supported commands is available L<here|commands>.
       
   225 
       
   226 =head2 Scripting Support
       
   227 
       
   228 F<fshell> supports simple scripting to allow more than one command to be run in succession. Scripts can be invoked in two ways:
       
   229 
       
   230 =over 5
       
   231 
       
   232 =item *
       
   233 
       
   234 By running fshell with the script file name as an argument. If a path isn't given, the location F<\system\console\scripts> is searched on all drives if the script isn't found in the current working directory. For example:
       
   235 
       
   236   c:\>fshell myscript.script # checks for c:\myscript.script and ?:\system\console\scripts\myscript.script
       
   237   c:\>fshell e:\scripts\something # tries to run e:\scripts\something
       
   238   c:\>fshell myscript # checks for c:\myscript, ?:\system\console\scripts\myscript and finally ?:\system\console\scripts\myscript.script
       
   239 
       
   240 =item *
       
   241 
       
   242 By 'executing' the script file itself (this is normally done by selecting the file in the handset's file manager). To support this F<fshell> provides a recognizer plug-in that recognizes files that begin with 'C<#!fshell>'. For example:
       
   243 
       
   244   #!fshell
       
   245   echo 'An example script'
       
   246 
       
   247 Note, the text following 'C<#!>' doesn't need to be 'C<fshell>' - the recognizer will attempt to launch any executable you care to name, providing the script file name in its command line.
       
   248 
       
   249 =back
       
   250 
       
   251 Scripts may contain any number of valid F<fshell> command lines. Separate script files may be run in the context of a single F<fshell> instance by using the L<source|source> command. Note, when F<fshell> runs a script, it defines the following environment variables within itself before doing so:
       
   252 
       
   253 =over 5
       
   254 
       
   255 =item * C<SCRIPT_PATH>
       
   256 
       
   257 Contains the absolute path (with trailing slash) to the directory that contains the script being executed. This may be used by the script to, for example, load other source files (using L<source|source>) that exist in the same directory as itself.
       
   258 
       
   259 =item * C<SCRIPT_NAME>
       
   260 
       
   261 Contains the name of the script file being executed.
       
   262 
       
   263 =item * C<SCRIPT_LINE>
       
   264 
       
   265 Contains the line number of the script that is currently being executed.
       
   266 
       
   267 =item * C<$0> ("dollar zero")
       
   268 
       
   269 The absolute path of the script. Equivalent to C<$SCRIPT_PATH$SCRIPT_NAME>.
       
   270 
       
   271 =item * C<$1, $2, etc>
       
   272 
       
   273 If any command line arguments to the script were specified, they are set in the environment. The first argument goes in $1, the second (if present) in $2 etc. For example, a script called envtest.script that just consisted of a call to C<env> would print out something like:
       
   274 
       
   275   c:\>fshell envtest.script AnArgument "Another argument" Something Else
       
   276   0=c:\envtest.script
       
   277   1=AnArgument
       
   278   2=Another argument
       
   279   3=Something
       
   280   4=Else
       
   281   ?=0
       
   282   ARG_COUNT=4
       
   283   PWD=c:\
       
   284   SCRIPT_LINE=1
       
   285   SCRIPT_NAME=envtest.script
       
   286   SCRIPT_PATH=c:\
       
   287 
       
   288 =item * C<ARG_COUNT>
       
   289 
       
   290 The number of arguments to the script. If $ARG_COUNT is 2, there are 2 arguments (in addition to $0), which are named $1 and $2.
       
   291 
       
   292 =back
       
   293 
       
   294 =head2 Global Command Line Options
       
   295 
       
   296 All commands, including fshell itself, have the following common set of command line options which control where/how the command runs. These global options are not generally listed when you run C<command --help>. There are no short alternatives for these options.
       
   297 
       
   298 =over 5
       
   299 
       
   300 =item * --console <console_implementation>
       
   301 
       
   302 This allows the console implementation F<.dll> to be overridden. Ordinarily, commands share the console of the F<fshell> instance that launched them. By explicitly specifying a console implementation, a different kind of console may be used to that of the parent F<fshell> instance. Another use of this option is to force the console provider to create a new console window for the command to run in. Note however that not all console implementations support multiple windows. See the L<consoles documentation|consoles> for more information.
       
   303 
       
   304 =item * --console-title <text>
       
   305 
       
   306 Only has an effect when used in conjunction with C<--console>. Allows the title of the overridden console window to be specified. Some consoles use this parameter to pass in additional configuration options.
       
   307 
       
   308 =item * --console-size <width>, <height>
       
   309 
       
   310 Only has an effect when used in conjunction with C<--console>. Allows the character width and height of the overridden console window to be specified. Note, some console implementations impose restrictions on the minimum and maximum size of their console windows. Generally this option isn't needed any more because in most configurations fshell or the console is capable of auto-detecting the size.
       
   311 
       
   312 =item * --persistent-console <name>
       
   313 
       
   314 Creates a new L<persistent console|persistent_consoles> to be used as the console for the command. Cannot be used in conjunction with C<--console>.
       
   315 
       
   316 =back
       
   317 
       
   318 =head2 Advanced command-line syntax
       
   319 
       
   320 Short options may be run together in one block, the only restriction being that only the last option in the block may take an argument. For example the following are equivalent:
       
   321 
       
   322     kill --all --thread --match *undertaker
       
   323     kill -a -T -m *undertaker
       
   324     kill -aTm *undertaker
       
   325 
       
   326 Commands that have options that can be specified multiple times can be called in a number of different ways, partly depending on the type of the option. In the most basic case, you can specify the long or the short option repeatedly:
       
   327 
       
   328     echo --attributes bold --attributes underscore "hello!"
       
   329     echo -a bold -a underscore "hello!"
       
   330 
       
   331 For integer options, you can use the above or you can use commas. All of the below are valid fshell syntax and mean exactly the same:
       
   332 
       
   333     btrace --filter 1 --filter 3
       
   334     btrace --filter 1,3
       
   335     btrace -f 1,3
       
   336     btrace -f1,3
       
   337 
       
   338 For boolean options, you can additionally specify the short option multiple times in the same block. All of the below mean the same:
       
   339 
       
   340     fcontacts -v -v list
       
   341     fcontacts --verbose -v list
       
   342     fcontacts -vv list
       
   343 
       
   344 For most commands, it doesn't matter where you put the options - they can go before, after or mixed in with the arguments. The following are all equivalent:
       
   345 
       
   346     cat --binary file1 file2
       
   347     cat -b file1 file2
       
   348     cat file1 file2 -b
       
   349     cat file1 -b file2
       
   350 
       
   351 The only exception to this is commands that are designed to take other command-lines as their arguments. These will not parse options themselves if they appear as part of the arguments. For example the C<repeat> command will not parse C<-k> if it appears during the C<command> argument, even though C<-k> is a valid option for L<repeat|fshell::commands::repeat>. Therefore:
       
   352 
       
   353     repeat -k 3 ps
       
   354 
       
   355 is different to:
       
   356 
       
   357     repeat 3 ps -k
       
   358 
       
   359 The former means "repeat C<ps> three times, and specify the C<-k> repeat option". The latter means "repeat C<ps -k> three times". Commands that parse in this way can be identified by the phrase "Any further arguments or options will be coalesced into this one." which appears in their documentation. They are specifed in CIF files using the C<last> keyword. The precise rule for how C<last> behaves can be stated as: If the command line following the C<last> argument would need quoting or escaping to make it a single string argument, the string is taken literally as-is. Otherwise, the normal expansions take place:
       
   360 
       
   361     c:\>echo This^ gets^ expanded^ as^ expected
       
   362     This gets expanded as expected
       
   363     c:\>echo "Quoting the entire argument works as normal as well"
       
   364     Quoting the entire argument works as normal as well
       
   365 
       
   366 But a command line that has unescaped spaces or quotes will cause the entire thing to be taken literally:
       
   367 
       
   368     c:\>echo This is taken as one string even though it has spaces and 'unbalanced quotes"
       
   369     This is taken as one string even though it has spaces and 'unbalanced quotes"
       
   370     c:\>echo Note how escapes like ^r^n aren't expanded
       
   371     Note how escapes like ^r^n aren't expanded
       
   372     c:\>echo "But if it's all in quotes, escapes like ^r^n are expanded"
       
   373     But if it's all in quotes, escapes like 
       
   374      are expanded
       
   375 
       
   376 Environment variables are always expanded unless the entire argument is enclosed in 'single quotes'.
       
   377 
       
   378 ==see-also
       
   379 
       
   380 L<fshell commands|commands>
       
   381 
       
   382 L<consoles|consoles>
       
   383 
       
   384 L<CIF file syntax|cif_syntax>
       
   385 
       
   386 ==argument filename script_name optional
       
   387 
       
   388 The name of a script file to be executed. If a path isn't specified, and C<script_name> is not a file in the current working directory, the directory F<\system\console\scripts> is searched on all drives.
       
   389 
       
   390 ==argument string script_args optional last
       
   391 
       
   392 Arguments to be send to the script.
       
   393 
       
   394 ==option string e exec
       
   395 
       
   396 Execute the specified one line script.
       
   397 
       
   398 ==option bool k keep-going
       
   399 
       
   400 When running in script mode, keep processing the script even if a previous command has returned an error. Without this option set, an error would cause the processing to abort (and fshell to exit with the error code) unless either C<&&>, C<||> or C<&|> was used to handle the error. For the convenience of scripts that may wish to pass on the flag to sub-instances of fshell, if this flag is specified the environment variable C<KEEP_GOING> is defined.
       
   401 
       
   402 ==copyright
       
   403 
       
   404 Copyright (c) 2006-2010 Accenture. All rights reserved.
       
   405