home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / programs / system / csh / tips.doc < prev    next >
Text File  |  1995-02-27  |  6KB  |  210 lines

  1. Some random tips & tricks I collected:
  2.  
  3.  
  4.     EDITING
  5.  
  6.  
  7. The very common situation:
  8. $ mkdir documents
  9. $ cd documents
  10. can be abbreviated to:
  11. $ mk documents
  12. $ [CTRL-T]              (inserts all but first word of previous line)
  13.  
  14.  
  15. Also very common:
  16. $ mv document document1
  17. $ mv document[CTRL-P]1
  18. The CTRL-P function duplicates the previous word on the command line
  19.  
  20.  
  21. You  might  have  wondered  what  CTRL-N  (leave current line) is good for.
  22. Assume, for example, you just typed
  23. $ rm dh1:graphics/lo-res/gorilla
  24. when  it comes to your mind that would prefer to keep a copy of that pic on
  25. diskette.  Many would now delete this command line.  Being a smart guy, you
  26. do the following:
  27. $ [CTRL-N]              (leaves this command line alone)
  28. $ co[CTRL-T] df0:
  29. $ [Up-Arrow][Up-Arrow]  (gets back the command line you left)
  30.  
  31.  
  32. In case you don't know what history completion is:
  33. $ search *.c *.h makefile foobar
  34. $ ram:
  35. $ dir
  36. $ rm tmpfile
  37. Now if want to repeat the search command, enter
  38. $ se[Shift-Up-Arrow]
  39. which brings up the the last command that started with 'se'.
  40.  
  41.  
  42. If you ever cycle too far using the TAB key, skipping the entry you
  43. orignally wanted, you can get back one entry using CTRL-U [undo].
  44. The same applies if you entered an abbreviation, press TAB but get
  45. aware that the abbrev was too short.
  46.  
  47.  
  48. If you want to delete the file
  49. $ rm dh2:comm/uucp/mail/junk/409
  50. and you're far away from that directory, enter
  51. $ rm ju[ESC-c]409          (enters the resulting path of cd ju)
  52.  
  53.  
  54. The  same function is also usable for 'cd'.  Assume you have several 'junk'
  55. directories:
  56. $ ju[ESC-c][CTRL-R][CTRL-R][CTRL-R]
  57. Like  this  you'll cycle through the junk directories.  When you've got the
  58. right one, press enter.
  59.  
  60.  
  61. Assume  there  are the files comm1.c, comm2.c, and comm3.c as well as their
  62. corresponding .o files.  You want comm3.c:
  63. $ co[Shift-Tab]1[Tab]
  64. Of course this is more useful with longer file names.
  65.  
  66.  
  67. You can tab file name expand any patterns, not only abbreviations.  Assume
  68. you want to delete all .c files in the current directory but the last:
  69. $ rm *.c[ESC-Tab][CTRL-W]
  70. In addition, you get to see all the files once again before deleting them.
  71.  
  72.  
  73. Next one: You have entered:
  74. $ dir
  75. $ foreach i ( *.c ) "e >>ram:temp $i
  76. $ more ram:temp
  77. and you would like to execute the same three statements again, enter:
  78. $ [Up-Arrow][Up-Arrow][Up-Arrow][ESC-Return][CTRL-R][CTRL-R]
  79.  
  80.  
  81. I  know  that  the editing is not very user friendly.  This is because it's
  82. quite  hard  and troublesome to get raw keycodes from the console, and it's
  83. impossible  to  get  them  from a VT200 terminal.  Therefore I had to stick
  84. with CTRL and ESC combinations. Once you have learnt them (some of them are
  85. similar to EMACS), you can save lots of typing.
  86.  
  87.  
  88.     COMMANDS
  89.  
  90.  
  91. My  advice  here  is clear:  Use aliases, aliases, aliases.  In order to be
  92. able  to  create  them as quickly as possible, create an alias (e.g.  'le')
  93. that edits your login file, plus another one (e.g.  'lx'), that re-executes
  94. it.   My  login  contains  almost  only aliases, everthing else I've put in
  95. 'firstlogin.sh'.
  96.  
  97.  
  98. If you don't like the default options of one command, you can add more of
  99. them using an alias:
  100. $ alias dir "dir -q
  101. From now on, blocks will no longer be displayed in 'dir'.
  102.  
  103.  
  104. If your aliases have arguments, e.g.
  105. $ alias sc "search *.c
  106. problems arise when you try to specify options. e.g. case sensitivity:
  107. $ sc -c "hello world
  108. this will obviously not work. That's what @pickopts is good for:
  109. $ alias sc "%a search @pickopts( $a ) *.c @pickargs( $a )
  110.  
  111.  
  112. Once you have more aliases, it is useful to keep them sorted.  You might
  113. also document them: Create a file 'aliases.doc', and perform
  114. $ set _man aliases.doc csh.doc
  115. That way, you can document them in a separate file.
  116.  
  117.  
  118. If you would like to create aliases that accept arguments, you can implement
  119. them using 'if -o'.
  120. $ alias good "%a if -o v $a;echo -n "very ";endif;echo good work, @arg( $a )
  121. $ good sam          --> good work, sam
  122. $ good -v sam       --> very good work, sam
  123.  
  124.  
  125. 'cat' can be used to create small text files:
  126. $ cat >myfile
  127. hello
  128. [CTRL-\]
  129. The key combination CTRL-\ creates an end-of-file character.
  130.  
  131.  
  132.     FUNCTIONS
  133.  
  134.  
  135. @age is very useful for archiving scripts:
  136. $ foreach i ( * ) "if @age( $i ) > 30;cp -m $i backup:;endif
  137.  
  138.  
  139. @clinum can be used for making 'break' and 'pri' more flexible:
  140. $ alias break "%a break @clinum( $a )
  141. Now you can, for example, 'break cc'. Cli numbers are still allowed.
  142.  
  143.  
  144. @complete simulates the effect of tab file name completion. That
  145. way, you need no longer press TAB for it:
  146. $ alias edit "%a ced @complete( $a * )
  147.  
  148.  
  149. @confirm can be used for a safe 'rm':
  150. $ alias rm "%a rm @confirm( $a )
  151.  
  152.  
  153. @howmany is useful at startup:
  154. $ if $howmany = 1;window -l;endif
  155.  
  156.  
  157. @intersect, @union and @without are well suited for a lot of applications.
  158. If you store, for example, all files a friend of yours owns, in the variable
  159. $him, (he can do a 'dir -np .../ >temp', you then do a 'readf him <temp'),
  160. and your files in $me, then you can learn what he has and you don't using
  161. $ echo @without( $him , $me )
  162. To ignore different path names, use
  163. $ set him @basename( $him )
  164. If you have the the file names without the path, you can find out the path
  165. by 'search'ing the file temp.
  166.  
  167.  
  168. @opt and @arg are needed whenever you have an alias that already specififies
  169. some arguments, but allows the user to specify additional options.
  170. $ alias sc "%a search @opt( $a ) *.c @arg( $a )
  171.  
  172.  
  173. @volume can be used to test if there is a disk in a certain drive. It will
  174. suppress requesters and return an empty string if no disk present.
  175.  
  176.  
  177.     VARIABLES
  178.  
  179.  
  180. $_except can be made local. In that case you have a special exception 
  181. handling for the current alias or batch file.
  182.  
  183.  
  184. $_man may contain the names of more than one .doc file. That way, you
  185. may add documentation to your own aliases.
  186.  
  187.  
  188. When working with large files in pipes, you might want to set $_pipe
  189. to a directory on your hard disk.
  190.  
  191.  
  192.     PARSER
  193.  
  194.  
  195. If you need to append a string to a variable, you can do it like this:
  196. $ set foo bar
  197. $ echo $foo""bara    --> barbara
  198. The "" isn't necessary if the first character of the string to be appended
  199. is neither a letter nor digit nor _.
  200.  
  201.  
  202. To make sure no internal command is executed, capitalize the first letter
  203. of your command:
  204. $ Dir ram: ALL
  205.  
  206.  
  207. To override existing aliases to a command, enter:
  208. $ alias echo "xxxxxx
  209. $ \echo hello    -->  hello
  210.