Friday, July 25, 2014

Features of C shell

Each shell has its own set of features. Those of the C Shell are discussed below.
  • Command history: The history mechanism maintains a list of recently used command lines, called events. Provides a shorthand for reexecuting previous commands. To use history:
    1. Set the history variable:
    2.      set history = 100
      
      
    3. Issue the history command and view the output:
    4.      history
      
      
      
           35  12:34   sort < unsorted > sorted.list
      
           36  12:34   cat sorted.list
      
           37  12:35   ls * > unsorted
      
           38  12:35   cat unsorted
      
           39  12:35   ls
      
           40  13:06   history
      
           41  13:08   alias
      
           42  13:11   ls
      
           43  13:11   vi .cshrc
      
      
    5. To save history events across all login sessions, set the savehistory variable:
    6.      set savehistory = 50
      
      
  • Event reexecution: Allows you to specify a shorthand for reexecuting a previous event. Works with the history list.
  •      !!          - repeats last command 
    
         !number     - repeats numbered command from history list
    
         !string     - repeats last command starting with string 
    
    
  • Modifying previous events: Allows you to correct typos in previous command, or modify it to create a new command.
  •      ^old^new             - changes the string "old" to the 
    
                                string "new" in the last command  
    
                                issued 
    
         !number:s/old/new/   - changes numbered command from 
    
                                history list; substitutes the 
    
                                string "old" with the string "new".
    
                                Note that there is no space 
    
                                between number and : 
    
             
    
    
  • Aliases: The alias command allows you to define new commands. Useful for creating shorthands for longer commands. The syntax is.
  •      alias  entered_command  executed_command
    
    
    Some examples:
         alias  m     more
    
         alias  rm    "rm -i"
    
         alias  h     "history -r | more"
    
         alias  xpvm  /source/pd/xpvm/src/RS6K/xpvm
    
    
    To view all current aliases:
         alias
    To remove a previously defined alias:
         unalias alias_name
  • Filename Generation: When you give the shell abbreviated filenames which contain special characters (metacharacters), it can generate filenames which match existing files. Some examples appear below:
  •      
    
         ls  *.txt    - list files with .txt suffix 
    
         ls [abc]*    - list files with names that start with a, 
    
                        b or c
    
         lpr prog?.c  - print files named prog?.c where ? is 
    
                        any character
    
         cd ~jsmith   - change to user jsmith's home directory
    
    
    You can "turn off" filename generation by setting the noglob variable. This will permit special characters to be interpreted literally. For example:
         set noglob
  • Filename Completion: The shell will complete a filename for you if you type in only enough characters to make the name unique. This feature is a great time saver and helps to prevent typos when trying to type long filenames.
  • To use filename completion, you need to set filec, either on the command line or in one of your initialization files.
         set filec
    Then, when specifying a filename, type the part which is unique and hit the escape key (C shell) or tab key (TC Shell). For example, if you had a directory with a long name, such as "Introduction.UNIX.Filesystems", you could cd to that directory by using the cd command with only a portion of the file's name, provided that the portion you specify is unique (no other files have similar names)
         
    
         cd Intro
    
    
    Note: typing a portion of a filename and then hitting CTRL-D instead of ESCape or TAB will display a list of the filenames which match.

Reactions:

0 comments:

Post a Comment