chapter 9: the tc shell
DESCRIPTION
Chapter 9: The TC Shell. Everything you thought you knew is now wrong. In this chapter …. Background Accessing tcsh Startup Files Commonality with bash Standard error Variables Control structures and builtins. Background. TC Shell - an expansion of the C Shell from BSD - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Chapter 9: The TC Shell](https://reader036.vdocuments.us/reader036/viewer/2022081419/568160c7550346895dcff665/html5/thumbnails/1.jpg)
Chapter 9:The TC Shell
Everything you thought you knew is now wrong
![Page 2: Chapter 9: The TC Shell](https://reader036.vdocuments.us/reader036/viewer/2022081419/568160c7550346895dcff665/html5/thumbnails/2.jpg)
In this chapter …• Background• Accessing tcsh• Startup Files• Commonality with bash• Standard error• Variables• Control structures and builtins
![Page 3: Chapter 9: The TC Shell](https://reader036.vdocuments.us/reader036/viewer/2022081419/568160c7550346895dcff665/html5/thumbnails/3.jpg)
Background• TC Shell - an expansion of the C Shell from BSD• The ‘T’ comes from TENEX and TOPS-20 OSes• Meant to add features such as command
completion to csh• Not a very good scripting language – bash is
much better• Most features in bash are in tcsh, just might have
different syntax
![Page 4: Chapter 9: The TC Shell](https://reader036.vdocuments.us/reader036/viewer/2022081419/568160c7550346895dcff665/html5/thumbnails/4.jpg)
Shell Scripting Caveat• Recall that we can specify which shell to use
for a script by starting the first line with #!/path_to_shell
• Without this line, tcsh will use sh to execute the script unless you run the script with tcsh explicitly
• Different than bash and other shells• Even tcsh admits it’s not great
![Page 5: Chapter 9: The TC Shell](https://reader036.vdocuments.us/reader036/viewer/2022081419/568160c7550346895dcff665/html5/thumbnails/5.jpg)
Accessing tcsh• Easiest way is to just issue tcsh• Want to change your login shell to tcsh?
– chsh• Exiting tcsh
– exit– logout (only if login shell)– CTRL-D (if ignoreeof not set)
![Page 6: Chapter 9: The TC Shell](https://reader036.vdocuments.us/reader036/viewer/2022081419/568160c7550346895dcff665/html5/thumbnails/6.jpg)
Startup Files• Logon shell
– /etc/csh.cshrc– /etc/csh.logon– ~/.tcshrc or ~/.cshrc– ~/.login
• Non-logon shell– /etc/csh.cshrc– ~/.tcshrc or ~/.cshrc
![Page 7: Chapter 9: The TC Shell](https://reader036.vdocuments.us/reader036/viewer/2022081419/568160c7550346895dcff665/html5/thumbnails/7.jpg)
More files• On logout
– /etc/csh.logout– ~/.logout
• History events loaded from– ~/.history
![Page 8: Chapter 9: The TC Shell](https://reader036.vdocuments.us/reader036/viewer/2022081419/568160c7550346895dcff665/html5/thumbnails/8.jpg)
Things in common with bash• Command line expansion
– Called substitution in tcsh docs• History
– history builtin works the same– ! history references work the same– Instead of HISTSIZE and HISTFILESIZE, tcsh
uses history and savehist– If variable histlit is set, history shows literal
commands before command line substitution
![Page 9: Chapter 9: The TC Shell](https://reader036.vdocuments.us/reader036/viewer/2022081419/568160c7550346895dcff665/html5/thumbnails/9.jpg)
tcsh vs. bash con’t• Aliases
– Syntax: alias name “value”– Allows you to reference command line
arguments using \!* or \!:n– Special aliases
•beepcmd – instead of bell•cwdcmd – whenever you change directories•periodic – a periodic command to run (tperiod)•precmd – runs just before shell prompt•shell – absolute path to use for scripts w/o #!
![Page 10: Chapter 9: The TC Shell](https://reader036.vdocuments.us/reader036/viewer/2022081419/568160c7550346895dcff665/html5/thumbnails/10.jpg)
tcsh vs. bash con’t• Job control
– Almost identical, slightly different for multiple processes spawned at once
• Filename substitution– *, ?, [], {}, ~ all the same– ~+,~- not available
• Directory stack – same• Command Substitution $() – NOT available
– Use `command` instead
![Page 11: Chapter 9: The TC Shell](https://reader036.vdocuments.us/reader036/viewer/2022081419/568160c7550346895dcff665/html5/thumbnails/11.jpg)
Standard Error• tcsh doesn’t have an easy way to capture
standard error like bash (i.e. 2> )• Instead we have to use >& to combine
standard error and standard out• So grab standard out first, then combine out
and error to capture error• Ex: (cat x y > results) >& errors
![Page 12: Chapter 9: The TC Shell](https://reader036.vdocuments.us/reader036/viewer/2022081419/568160c7550346895dcff665/html5/thumbnails/12.jpg)
Word Completion• Tab completion is similar in tcsh• Start with an ambiguous reference then hit
tab• If there are multiple matches, it will maximize
the length of the prefix• Will *not* show a list of possible matches
unless you press CTRL-D
![Page 13: Chapter 9: The TC Shell](https://reader036.vdocuments.us/reader036/viewer/2022081419/568160c7550346895dcff665/html5/thumbnails/13.jpg)
Variables• In tcsh, there are two scopes, local and
global• To declare a local variable, use:
set variable = value– Note the spaces – different than bash
• To declare a local integer variable:@ variable = value
• To declare a global (avail. to child procs):setenv variable value
![Page 14: Chapter 9: The TC Shell](https://reader036.vdocuments.us/reader036/viewer/2022081419/568160c7550346895dcff665/html5/thumbnails/14.jpg)
Variables con’t• Just like bash, use a $ to reference a
variable’s contents (also ${ } )• unset, unsetenv removes variables• To declare an array of strings:
set variable = ( values … )• To reference single entries use [] operator
(base 1)echo variable[2] set variable[4] = “Value”
![Page 15: Chapter 9: The TC Shell](https://reader036.vdocuments.us/reader036/viewer/2022081419/568160c7550346895dcff665/html5/thumbnails/15.jpg)
Numeric Variables• The @ builtin lets you work with numeric
expressions• Ex.
@ variable = ( $count + 4 ) / 5• Caveat – separate each element by a space• Available operators:
=, +=, -=, *=, /=, %=, +, -, *, /, %
![Page 16: Chapter 9: The TC Shell](https://reader036.vdocuments.us/reader036/viewer/2022081419/568160c7550346895dcff665/html5/thumbnails/16.jpg)
Numeric Variables con’t• To make an array of numeric variables, you
actually have to use setset variable = (1 2 3 4 5)
• Then use @ to access the array@ variable[2] = 2
![Page 17: Chapter 9: The TC Shell](https://reader036.vdocuments.us/reader036/viewer/2022081419/568160c7550346895dcff665/html5/thumbnails/17.jpg)
More variable goodness• $#variable – displays the number of
elements in a variable array• $?variable – displays whether the variable
is set (1 for set, 0 for not set)• To read user input into a variable, set the
variable to “$<“– E.g. in a script
•echo –n “Enter a value:”set usr_input = “$<“
![Page 18: Chapter 9: The TC Shell](https://reader036.vdocuments.us/reader036/viewer/2022081419/568160c7550346895dcff665/html5/thumbnails/18.jpg)
Important Shell Variables• autologout – set timeout period• cwd – contains current working directory• histfile – contains location of history• history – how many history items to keep• home – your home directory• mail – where your mail is stored• owd – previous (old) working directory
![Page 19: Chapter 9: The TC Shell](https://reader036.vdocuments.us/reader036/viewer/2022081419/568160c7550346895dcff665/html5/thumbnails/19.jpg)
Shell Variables, con’t• histlit – show literal commands in history• ignoreeof – ignore CTRL-D• nobeep – disables shell beeps• noglob – turns of file globbing• rmstar – prompt for rm * commands• visiblebell – causes screen to flash for bells
![Page 20: Chapter 9: The TC Shell](https://reader036.vdocuments.us/reader036/viewer/2022081419/568160c7550346895dcff665/html5/thumbnails/20.jpg)
Shell Variables, con’t• argv – array of command line args
– $n , $*– Use $#argv to get number of args
![Page 21: Chapter 9: The TC Shell](https://reader036.vdocuments.us/reader036/viewer/2022081419/568160c7550346895dcff665/html5/thumbnails/21.jpg)
Misc• bindkey• Control structures