857什么意思| 核桃和什么一起打豆浆| 饿得快是什么原因| 什么的小姑娘| 血小板低吃什么补得快| 妲是什么意思| 舌头无苔是什么原因| 睡不着觉去医院挂什么科| 产后42天挂什么科| 浩浩荡荡是什么意思| 致意是什么意思| 扳机指是什么原因造成的| 什么是老赖| 脚筋膜炎什么办法恢复的最快| 乐色是什么意思| 浓缩汁是什么意思| os是什么意思| 颜值控是什么意思| 神秘感是什么意思| 狗哭了代表什么预兆| 乳糖不耐受不能吃什么| 中性粒细胞偏低是什么意思| 胎盘成熟度2级是什么意思| 婴儿增强免疫力吃什么| 6是什么意思| 直接胆红素是什么| 新生儿黄疸吃什么药| 小便有刺痛感什么原因| 失聪是什么原因造成的| 陪产假什么时候开始休| 7月出生的是什么星座| 害羞的反义词是什么| ca登录是什么意思| 农历10月26日是什么星座| 元辰是什么意思| 鼻子旁边长痘是什么原因| 梅毒症状男有什么表现| 崔字五行属什么| 没有痔疮大便出血是什么原因| 蜘蛛痣是什么原因引起的| 是的是什么意思| 正月十九是什么日子| 股癣是什么样的| 孕初期需要注意些什么| 一班三检是指什么| 喝栀子茶有什么好处| 鱼为什么睁着眼睛睡觉| 天山童姥练的什么武功| 着痹是什么意思| 状况是什么意思| 诺诺是什么意思| 鸟字旁的字和什么有关| 每天早上起来口苦是什么原因| 年柱将星是什么意思| 八四年属什么生肖| 孕晚期吃什么长胎不长肉| 种生基是什么意思| 心脏检查挂什么科| 十年结婚是什么婚| 金牛男最烦什么女孩| 红旗代表什么生肖| 果蝇是什么| 小酌怡情什么意思| 白电油对人体有什么危害| 什么是援交| pt代表什么| 吃什么都苦是什么原因| 金的部首是什么| 手胶是什么| 四十不惑是什么意思| 句加一笔是什么字| 肾火旺吃什么药| 大放厥词是什么意思| 小便尿不出来是什么原因| 1988年属什么今年多大| 下丘脑分泌什么激素| 卡蒂罗属于什么档次| 拉肚子不能吃什么| 梳头有什么好处| cpap是什么意思| 结肠ca是什么意思| 同性恋是什么意思| 大姨妈期间可以吃什么水果| 天生一对成伴侣是什么生肖| 大豆油是什么豆做的| 看病人送什么花| 吃钙片有什么好处| 狗消化不良吃什么药| 梦见自己孩子死了是什么意思| 喝酒会得什么病| 排卵期是指什么时候| 什么的李子| vvip是什么意思| 次月是什么意思| 为什么不能天天喝豆浆| 胆汁有什么作用| 淇字五行属什么| 1月出生是什么星座| 迪丽热巴的全名叫什么| 本科是什么| 走路快的人是什么性格| 高密度脂蛋白偏高是什么意思| 养寇自重什么意思| 什么样的雪莲| 紧急避孕药有什么副作用| 土豆粉是什么做的| 吃哈密瓜有什么好处| 手一直抖是什么原因| 农历8月13日是什么星座| 眼睛经常长麦粒肿是什么原因| 康妇炎胶囊主治什么| 唐朝为什么灭亡| 自渎是什么意思| 今年54岁属什么生肖| 尿检肌酐高是什么原因| 房颤是什么意思| 什么的教学楼| 什么的蹲着| 谦虚什么意思| 36是什么生肖| 梦见狗打架是什么意思| 异位性皮炎是什么意思| 阿斯巴甜是什么| 咽喉炎有什么症状| 为什么一直打嗝| 耳后长痣代表什么意思| 2016年属什么生肖| 高血钙有什么症状| 上眼皮浮肿是什么原因| 尼古丁是什么| 什么动物的牙齿最多| 喝酒后头晕是什么原因| 背靠背是什么牌子| 舌苔发黄吃什么药| 人为什么会便秘| 稍纵即逝什么意思| 省委巡视组组长什么级别| 蛋白尿吃什么食物好| 神态是什么意思| 蔗糖脂肪酸酯是什么| 全麻后为什么不能睡觉| 尿酸偏低是什么原因| 手发胀是什么原因| 喝完酒吃什么解酒最快| 梦见打老婆是什么预兆| 什么杀精子最厉害| 泵头是什么| 右肩膀疼是什么原因| 短纤是什么| 空腹喝什么茶| 血小板低吃什么| 什么蔬菜补钾| 泡桐是什么| 郁结是什么意思| 衣服五行属什么| 快速补血吃什么| 自我意识是什么意思| 什么叫活佛| 什么油适合炒菜| 语塞是什么意思| 学前教育学什么| 肾虚吃什么中成药| 迷津是什么意思| 外传是什么意思| 江西什么最出名| 马云是什么大学毕业的| 猪古代叫什么| 老人吃什么水果好| 荪是什么意思| 维生素b6主治什么病| 穿梭是什么意思| 什么是对数| 后脑勺疼痛什么原因引起的| 大象什么颜色| 上海的特产是什么| 左侧上颌窦炎症是什么意思| 心境什么意思| 肺主皮毛是什么意思| 百思不得其解是什么意思| 高血压注意什么| 洛阳有什么大学| 肛门不舒服是什么原因| 经常打嗝放屁是什么原因| 起湿疹是什么原因造成的| 腰疼肚子疼是什么原因引起的| 灰色配什么颜色| 红烧鱼用什么鱼| 伊朗用什么货币| 十一月十一号是什么星座| 一什么绿毯| 文号是什么| 意守丹田是什么意思| 轴向是什么意思| 答非所问是什么意思| 过期的酸奶有什么用| 看舌头应该挂什么科| 小孩子肚子疼吃什么药| 含羞草长什么样| 十羊九不全是什么意思| 介怀是什么意思| 蒸米饭时加什么好吃| 介质是什么意思| 逃出生天什么意思| 立夏节吃什么| 穿什么衣服| 50年婚姻是什么婚| 女生排卵期有什么症状| 火加木是什么字| 胸闷气短是什么原因造成的| 贼是什么生肖| 阴道恶臭是什么原因| 六月初十是什么日子| 豚是什么动物| 庚寅五行属什么| 司空见惯的惯是什么意思| 眼睛屈光不正是什么| 什么是遗憾| 因地制宜是什么意思| 茯苓是什么| 食物过敏吃什么药| 什么是癣| 脚冰冰凉是什么原因| 双肺纹理粗重什么意思| 一到晚上就饿什么原因| 2月14日什么星座| 血红蛋白浓度偏高是什么原因| 胎儿头位是什么意思| 什么是我的| 儿童肠胃感冒吃什么药效果好| 女生月经不规律的原因是什么| 什么是传染病| 小酌怡情什么意思| 肠胀气是什么原因引起的| 一吃就吐是什么病症| 孙字五行属什么| 低密度脂蛋白高有什么症状| 太燃了是什么意思| 低聚果糖是什么东西| 芒果可以做什么美食| 心肌是什么意思| 滑石粉是什么| 经常困想睡觉是什么问题| 含五行属什么| 一个提手一个京念什么| 三顾茅庐的顾是什么意思| 吃什么助消化| 樊字五行属什么| 减肥喝什么茶最好最快| 世界上最长的英语单词是什么| 宫缩什么感觉| 头疼 吃什么药| 感染乙肝病毒有什么症状| 检查包皮挂什么科| 亚急性甲状腺炎吃什么药| 肝胆湿热吃什么中成药最好| 老火汤是什么意思| 我的手机是什么型号| 什么叫败血症| 正视是什么意思| 小便失禁是什么原因| 理性什么意思| 蚊香对人体有什么危害| 考药师证需要什么条件| 梅长苏结局是什么| 百度Jump to content

大家有投资民营车贷平台的吗?都在哪家平台投资?

From Wikipedia, the free encyclopedia
百度 中国未来研究会旅游分会副会长刘思敏指出,纯粹的美食之旅,需要游客有非常强烈的美食兴趣,通常价格不菲。

C shell
Original author(s)Bill Joy
Initial release1978; 47 years ago (1978)
Stable release
6.20.00 / 24 November 2016; 8 years ago (2025-08-05)[1]
Repository
Written inC
Operating systemBSD, UNIX, UNOS, Linux, macOS
TypeUnix shell
LicenseBSD license
C Shell running on Windows Services for UNIX

The C shell (csh or the improved version, tcsh) is a Unix shell created by Bill Joy while he was a graduate student at University of California, Berkeley in the late 1970s. It has been widely distributed, beginning with the 2BSD release of the Berkeley Software Distribution (BSD) which Joy first distributed in 1978.[2][3] Other early contributors to the ideas or the code were Michael Ubell, Eric Allman, Mike O'Brien and Jim Kulp.[4]

The C shell is a command processor which is typically run in a text window, allowing the user to type and execute commands. The C shell can also read commands from a file, called a script. Like all Unix shells, it supports filename wildcarding, piping, here documents, command substitution, variables and control structures for condition-testing and iteration. What differentiated the C shell from others, especially in the 1980s, were its interactive features and overall style. Its new features made it easier and faster to use. The overall style of the language looked more like C and was seen as more readable.

On many systems, such as macOS and Red Hat Linux, csh is actually tcsh, an improved version of csh. Often one of the two files is either a hard link or a symbolic link to the other, so that either name refers to the same improved version of the C shell. The original csh source code and binary are part of NetBSD.

On Debian and some derivatives (including Ubuntu), there are two different packages: csh and tcsh. The former is based on the original BSD version of csh[5][6] and the latter is the improved tcsh.[7][8]

tcsh added filename and command completion and command line editing concepts borrowed from the Tenex system, which is the source of the "t".[9] Because it only added functionality and did not change what already existed, tcsh remained backward compatible[10] with the original C shell. Though it started as a side branch from the original source tree Joy had created, tcsh is now the main branch for ongoing development. tcsh is very stable but new releases continue to appear roughly once a year, consisting mostly of minor bug fixes.[11]

Design objectives and features

[edit]

The main design objectives for the C shell were that it should look more like the C programming language and that it should be better for interactive use.

More like C

[edit]

The Unix system had been written almost exclusively in C, so the C shell's first objective was a command language that was more stylistically consistent with the rest of the system. The keywords, the use of parentheses, and the C shell's built-in expression grammar and support for arrays were all strongly influenced by C.

By today's standards, C shell may not seem particularly more C-like than many other popular scripting languages. But through the 1980s and '90s, the difference was seen as striking, particularly when compared to Bourne shell (also known as sh), the then-dominant shell written by Stephen Bourne at Bell Labs. This example illustrates the C shell's more conventional expression operators and syntax.

Bourne shell

#!/bin/sh
if [ $days -gt 365 ]
then
   echo This is over a year.
fi

C shell

#!/bin/csh
if ( $days > 365 ) then
   echo This is over a year.
endif

The Bourne sh lacked an expression grammar. The square bracketed condition had to be evaluated by the slower means of running the external test program. sh's if command took its argument words as a new command to be run as a child process. If the child exited with a zero return code, sh would look for a then clause (a separate statement, but often written joined on the same line with a semicolon) and run that nested block. Otherwise, it would run the else. Hard-linking the test program as both "test" and "[" gave the notational advantage of the square brackets and the appearance that the functionality of test was part of the sh language. sh's use of a reversed keyword to mark the end of a control block was a style borrowed from ALGOL 68.[12]

By contrast, csh could evaluate the expression directly, which made it faster. It also claimed better readability: Its expressions used a grammar and a set of operators mostly copied from C, none of its keywords were reversed and the overall style was also more like C.

Here is a second example, comparing scripts that calculate the first 10 powers of 2.

Bourne shell

#!/bin/sh
i=2
j=1
while [ $j -le 10 ]
do
   echo '2 **' $j = $i
   i=`expr $i '*' 2`
   j=`expr $j + 1`
done

C shell

#!/bin/csh
set i = 2
set j = 1
while ( $j <= 10 )
   echo '2 **' $j = $i
   @ i *= 2
   @ j++
end

Again because of the lack of an expression grammar, the sh script uses command substitution and the expr command. (Modern POSIX shell does have such a grammar: the statement could be written i=$((i * 2)) or : "$((i *= 2))".)

Finally, here is a third example, showing the differing styles for a switch statement.

Bourne shell

#!/bin/sh
for i in d*
do
   case $i in
      d?) echo $i is short ;;
      *) echo $i is long ;;
   esac
done

C shell

#!/bin/csh
foreach i ( d* )
   switch ( $i )
      case d?:
         echo $i is short
         breaksw
      default:
         echo $i is long
   endsw
end

In the sh script, ";;" marks the end of each case because sh disallows null statements otherwise.

Improvements for interactive use

[edit]

The second objective was that the C shell should be better for interactive use. It introduced numerous new features that made it easier, faster and more friendly to use by typing commands at a terminal. Users could get things done with a lot fewer keystrokes and it ran faster. The most significant of these new features were the history and editing mechanisms, aliases, directory stacks, tilde notation, cdpath, job control, and path hashing. These new features proved very popular, and many of them have since been copied by other Unix shells.

History

[edit]

History allows users to recall previous commands and rerun them by typing only a few quick keystrokes. For example, typing two exclamation marks ("!!")[13] as a command causes the immediately preceding command to be run. Other short keystroke combinations, e.g., "!$" (meaning "the final argument of the previous command"), allow bits and pieces of previous commands to be pasted together and edited to form a new command.

Editing operators

[edit]

Editing can be done not only on the text of a previous command, but also on variable substitutions. Operators range from simple string search/replace to parsing a pathname to extract a specific segment.

Aliases

[edit]

Aliases allow the user to type the name of an alias and have the C shell expand it internally into whatever set of words the user has defined. For many simple situations, aliases run faster and are more convenient than scripts.

Directory stack

[edit]

The directory stack allows the user to push or pop the current working directory, making it easier to jump back and forth between different places in the filesystem.

Tilde notation

[edit]

Tilde notation offers a shorthand way of specifying pathnames relative to the home directory using the "~" character.

Filename completion

[edit]

The escape key can be used interactively to show possible completions of a filename at the end of the current command line.

Cdpath

[edit]

Cdpath extends the notion of a search path to the cd (change directory) command: If the specified directory is not in the current directory, csh will try to find it in the cdpath directories.

Job control

[edit]

Well into the 1980s, most users only had simple character-mode terminals that precluded multiple windows, so they could only work on one task at a time. The C shell's job control allowed the user to suspend the current activity and create a new instance of the C shell, called a job, by typing ^Z. The user could then switch back and forth between jobs using the fg command. The active job was said to be in the foreground. Other jobs were said to be either suspended (stopped) or running in the background.

Path hashing

[edit]

Path hashing speeds up the C shell's search for executable files. Rather than performing a filesystem call in each path directory, one at a time, until it either finds the file or runs out of possibilities, the C shell consults an internal hash table built by scanning the path directories. That table can usually tell the C shell where to find the file (if it exists) without having to search and can be refreshed with the rehash command.

Overview of the language

[edit]

The C shell operates one line at a time. Each line is tokenized into a set of words separated by spaces or other characters with special meaning, including parentheses, piping and input/output redirection operators, semicolons, and ampersands.

Basic statements

[edit]

A basic statement is one that simply runs a command. The first word is taken as name of the command to be run and may be either an internal command, e.g., echo, or an external command. The rest of the words are passed as arguments to the command.

At the basic statement level, here are some of the features of the grammar:

Wildcarding

[edit]

The C shell, like all Unix shells, treats any command-line argument that contains wildcard characters as a pattern and replaces it with the list of all the filenames that match (see globbing).

  • * matches any number of characters.
  • ? matches any single character.
  • [...] matches any of the characters inside the square brackets. Ranges are allowed, using the hyphen.
  • [^...] matches any character not in the set.

The C shell also introduced several notational conveniences (sometimes known as extended globbing), since copied by other Unix shells.

Multiple directory-level wildcards, e.g., "*/*.c", are supported.

Since version 6.17.01, recursive wildcarding à la zsh (e.g. "**/*.c" or "***/*.html") is also supported with the globstar option.

Giving the shell the responsibility for interpreting wildcards was an important decision on Unix. It meant that wildcards would work with every command, and always in the same way. However, the decision relied on Unix's ability to pass long argument lists efficiently through the exec system call that csh uses to execute commands. By contrast, on Windows, wildcard interpretation is conventionally performed by each application. This is a legacy of MS-DOS, which only allowed a 128-byte command line to be passed to an application, making wildcarding by the DOS command prompt impractical. Although modern Windows can pass command lines of up to roughly 32K Unicode characters, the burden for wildcard interpretation remains with the application.

I/O redirection

[edit]

By default, when csh runs a command, the command inherits the csh's stdio file handles for stdin, stdout and stderr, which normally all point to the console window where the C shell is running. The i/o redirection operators allow the command to use a file instead for input or output.

  • > file means stdout will be written to file, overwriting it if it exists, and creating it if it doesn't. Errors still come to the shell window.
  • >& file means both stdout and stderr will be written to file, overwriting it if it exists, and creating it if it doesn't.
  • >> file means stdout will be appended at the end of file.
  • >>& file means both stdout and stderr will be appended at the end of file.
  • < file means stdin will be read from file.
  • << string is a here document. Stdin will read the following lines up to the one that matches string.

Redirecting stderr alone isn't possible without the aid of a sub-shell.

set filter = "$home"'/filter'
mkfifo "$filter"
cat "$filter" & ( ( ls /root/ || echo No access. ) > "$filter" ) >& /dev/null

Systems supporting file descriptors as files may use the following workaround.

( ( ( echo ok ; '' ) > /dev/fd/0 ) >& /dev/null < /dev/fd/1 ) | ( echo "$<" bye )

Joining

[edit]

Commands can be joined on the same line.

  • ; means run the first command and then the next.
  • && means run the first command and, if it succeeds with a 0 return code, run the next.
  • || means run the first command and, if it fails with a non-zero return code, run the next.

Piping

[edit]

Commands can be connected using a pipe, which causes the output of one command to be fed into the input of the next. Both commands run concurrently.

  • | means connect stdout to stdin of the next command. Errors still come to the shell window.
  • |& means connect both stdout and stderr to stdin of the next command.

Running concurrently means "in parallel". In a multi-core (multiple processor) system, the piped commands may literally be executing at the same time, otherwise the scheduler in the operating system time-slices between them.

Given a command, e.g., "a | b", the shell creates a pipe, then starts both a and b with stdio for the two commands redirected so that a writes its stdout into the input of the pipe while b reads stdin from the output of the pipe. Pipes are implemented by the operating system with a certain amount of buffering so that a can write for a while before the pipe fills but once the pipe fills any new write will block inside the OS until b reads enough to unblock new writes. If b tries to read more data than is available, it will block until a has written more data or until the pipe closes, e.g., if a exits.

Variable substitution

[edit]

If a word contains a dollar sign, "$", the following characters are taken as the name of a variable and the reference is replaced by the value of that variable. Various editing operators, typed as suffixes to the reference, allow pathname editing (e.g., ":e" to extract just the extension) and other operations.

Quoting and escaping

[edit]

Quoting mechanisms allow otherwise special characters, such as whitespace, wildcards, parentheses, and dollar signs, to be taken as literal text.

  • \ means take the next character as an ordinary literal character.
  • "string" is a weak quote. Enclosed whitespace and wildcards are taken as literals, but variable and command substitutions are still performed.
  • 'string' is a strong quote. The entire enclosed string is taken as a literal.

Double quotes inside double quotes should be escaped with "\"". The same applies to the dollar symbol, to prevent variable expansion "\$". For backticks, to prevent command substitution nesting, single quotes are required "'\`'".

Command substitution

[edit]

Command substitution allows the output of one command to be used as arguments to another.

  • `command` means take the output of command, parse it into words and paste them back into the command line.

The following is an example of nested command substitutions with Leaning toothpick syndrome:

echo "`echo "\"\`"echo "\"\\\"\\\`\""echo "\"\\\"\\\\\\\"\\\\\\\`\\\"\""echo "\"\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\`\\\\\\\"\\\"\""echo "\"\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\`\\\\\\\\\\\\\\\"\\\\\\\"\\\"\""pwd"\"\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\`\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\`\\\\\\\\\\\\\\\"\\\\\\\"\\\\\\\`\\\\\\\"\\\"\\\`\\\"\"\`\""`"

Background execution

[edit]

Normally, when the C shell starts a command, it waits for the command to finish before giving the user another prompt signaling that a new command can be typed.

  • command & means start command in the background and prompt immediately for a new command.

Subshells

[edit]

A subshell is a separate child copy of the shell that inherits the current state but can then make changes, e.g., to the current directory, without affecting the parent.

  • ( commands ) means run commands in a subshell.

Control structures

[edit]

The C shell provides control structures for both condition-testing and iteration. The condition-testing control structures are the if and switch statements. The iteration control structures are the while, foreach and repeat statements.

if statement

[edit]

There are two forms of the if statement. The short form is typed on a single line but can specify only a single command if the expression is true.

if ( expression ) command

The long form uses then, else and endif keywords to allow for blocks of commands to be nested inside the condition.

if ( expression1 ) then
    commands
else if ( expression2 ) then
    commands
    ...
else
    commands
endif

If the else and if keywords appear on the same line, csh chains, rather than nests them; the block is terminated with a single endif.

switch statement

[edit]

The switch statement compares a string against a list of patterns, which may contain wildcard characters. If nothing matches, the default action, if there is one, is taken.

switch ( string )
    case pattern1:
        commands
        breaksw
    case pattern2:
        commands
        breaksw
        ...
    default:
        commands
        breaksw
endsw

while statement

[edit]

The while statement evaluates an expression. If it is true, the shell runs the nested commands and then repeats for as long as the expression remains true.

while ( expression )
    commands
end

foreach statement

[edit]

The foreach statement takes a list of values, usually a list of filenames produced by wildcarding, and then for each, sets the loop variable to that value and runs the nested commands.

foreach loop-variable ( list-of-values )
    commands
end

repeat statement

[edit]

The repeat statement repeats a single command an integral number of times.

repeat integer command

Variables

[edit]

The C shell implements both shell and environment variables.[14] Environment variables, created using the setenv statement, are always simple strings, passed to any child processes, which retrieve these variables via the envp[] argument to main().

Shell variables, created using the set or @ statements, are internal to C shell. They are not passed to child processes. Shell variables can be either simple strings or arrays of strings. Some of the shell variables are predefined and used to control various internal C shell options, e.g., what should happen if a wildcard fails to match anything.

In current versions of csh, strings can be of arbitrary length, well into millions of characters.

Variables can be enlarged as needed. However, if it's desirable to work on a fixed size, the following syntax is preferred.

# Creates a variable large enough to hold 1024 elements.
set fixed = {,}{,}{,}{,}{,}{,}{,}{,}{,}{,}

Expressions

[edit]

The C shell implements a 32-bit integer expression grammar with operators borrowed from C but with a few additional operators for string comparisons and filesystem tests, e.g., testing for the existence of a file. Operators must be separated by whitespace from their operands. Variables are referenced as $name.

Operator precedence is also borrowed from C, but with different operator associativity rules to resolve the ambiguity of what comes first in a sequence of equal precedence operators. In C, the associativity is left-to-right for most operators; in C shell, it is right-to-left. For example,

// C groups from the left
int i = 10 / 5 * 2;
printf( "%d\n", i ); // prints 4
i = 7 - 4 + 2;
printf( "%d\n", i ); // prints 5
i = 2 >> 1 << 4;
printf( "%d\n", i ); // prints 16
# C shell groups from the right
@ i = 10 / 5 * 2
echo $i # prints 1
@ i = 7 - 4 + 2
echo $i # prints 1
@ i = ( 2 >> 1 << 4 )
echo $i # prints 0

The parentheses in the C shell example are to avoid having the bit-shifting operators confused as I/O redirection operators. In either language, parentheses can always be used to explicitly specify the desired order of evaluation, even if only for clarity.

Return values are limited to 8-bit. For exit expressions, the unary negation operator can be used for 32-bit evaluation.

exit ! ! 256 # Returns 1.

Reception

[edit]

Although Stephen Bourne himself acknowledged that csh was superior to his shell for interactive use,[15] it has never been as popular for scripting.

In 1983, both csh and Bourne shell were available for Charles River Data Systems' UNOS operating system among other UNIX tools under Bell Laboratories license.[16]

Initially, and through the 1980s, csh could not be guaranteed to be present on all Unix and Unix-like systems, but sh could, which made it a better choice for any scripts that might have to run on other machines. By the mid-1990s, csh was widely available, but the use of csh for scripting faced new criticism by the POSIX committee,[17] which specified that there should only be one preferred shell, the KornShell, for both interactive and scripting purposes. The C shell also faced criticism from others[18][19] over the C shell's alleged defects in syntax, missing features, and poor implementation.

  • Syntax defects: were generally simple but unnecessary inconsistencies in the definition of the language. For example, the set, setenv and alias commands all did basically the same thing, namely, associate a name with a string or set of words. But all three had slight but unnecessary differences. An equal sign was required for a set but not for setenv or alias; parentheses were required around a word list for a set but not for setenv or alias, etc. Similarly, the if, switch and looping constructs use needlessly different keywords (endif, endsw and end) to terminate the nested blocks.
  • Missing features: most commonly cited are the lack of ability to manipulate the stdio file handles independently and support for functions. Although lacking support for functions, aliases serve as workaround. For multiple lines of code, aliases must be within single quotes, and each end of line must precede a backslash (the end of the last line must precede a single quote to delimit the end of the alias). Recursion is favorable over aliases in scripts as workaround for functions (an example is given below).
  • The implementation: which used an ad hoc parser, has drawn the most serious criticism. By the early 1970s, compiler technology was sufficiently mature[20] that most new language implementations used either a top-down or bottom-up parser capable of recognizing a fully recursive grammar. It is not known why an ad hoc design was chosen instead for the C shell. It may be simply that, as Joy put it in an interview in 2009, "When I started doing this stuff with Unix, I wasn’t a very good programmer."[21] The ad hoc design meant that the C shell language was not fully recursive. There was a limit to how complex a command it could handle.

It worked for most interactively typed commands, but for the more complex commands a user might write in a script, it could easily fail, producing only a cryptic error message or an unwelcome result. For example, the C shell could not support piping between control structures. Attempting to pipe the output of a foreach command into grep simply didn't work. (The work-around, which works for many of the complaints related to the parser, is to break the code up into separate scripts. If the foreach is moved to a separate script, piping works because scripts are run by forking a new copy of csh that does inherit the correct stdio handles. It's also possible to break codes in a single file. An example is given below on how to break codes in a single file.)

Another example is the unwelcome behavior in the following fragments. Both of these appear to mean, "If 'myfile' does not exist, create it by writing 'mytext' into it." But the version on the right always creates an empty file because the C shell's order of evaluation is to look for and evaluate I/O redirection operators on each command line as it reads it, before examining the rest of the line to see whether it contains a control structure.

# Works as expected
if ( ! -e myfile ) then
   echo mytext > myfile
endif
# Always creates an empty file
if (! -e myfile) echo mytext > myfile
# Workaround (only for tcsh)
if (! -e myfile) eval "echo mytext > myfile"
# Second workaround (for csh and tcsh)
( exit ( -e myfile ) && ( ( echo mytext > myfile ) >& /dev/null || echo Cannot create file. ) || echo File exists.

The implementation is also criticized for its notoriously poor error messages, e.g., "0: Event not found.", which yields no useful information about the problem.

However, by practicing, it's possible to overcome those deficiencies (thus instructing the programmer to take better and safer approaches on implementing a script).

The "0: Event not found." error implies there aren't saved commands in the history. The history may not work properly in scripts, but having a pre-set of commands in a variable serves as workaround.

#!/bin/csh -f
set cmdlist = ( 'date # 1'\
'uname # 2'\
'tty # 3'\
'id # 4' )
echo -n 'Enter a number to execute a command from the history: '
set cmdexec = "$<"
( exit ( ! ( "$cmdexec" > 0 && \
"$cmdexec" <= "$#cmdlist" ) ) ) >& /dev/null
if ( "$status" ) then
  echo 'Invalid event number.'
  foreach cmd ( $cmdlist:q )
    echo "$cmd"
  end
  exit -1
endif
eval "$cmdlist[$cmdexec]"

Prefer breaking codes by recursing the script as workaround for functions.

#!/bin/csh -f
if ( ! "$?main" ) then
  if ( ! "$?0" ) then
    echo 'You must run this script by explicitly calling its file.'
    exit -1
  endif
  alias function 'set argv = ( \!* ) ; source "$main"'
  set main = "$0"
  set ret = "`function myfunc`"
  echo "$ret"
  exit
endif

goto "$1" ; shift

myfunc:
function myfunc2
echo "A function."
exit

myfunc2:
echo "Another function."
exit

Influence

[edit]
64-bit Hamilton C shell on a Windows 7 desktop

The C shell was extremely successful in introducing a large number of innovations including the history mechanism, aliases, tilde notation, interactive filename completion, an expression grammar built into the shell, and more, that have since been copied by other Unix shells. But in contrast to sh, which has spawned a large number of independently developed clones, including ksh and bash, only two csh clones are known. (Since tcsh was based on the csh code originally written by Bill Joy, it is not considered a clone.)

In 1986, Allen Holub wrote On Command: Writing a Unix-Like Shell for MS-DOS,[22] a book describing a program he had written called "SH" but which in fact copied the language design and features of csh, not sh. Companion diskettes containing full source for SH and for a basic set of Unix-like utilities (cat, cp, grep, etc.) were available for $25 and $30, respectively, from the publisher. The control structures, expression grammar, history mechanism and other features in Holub's SH were identical to those of the C shell.

In 1988, Hamilton Laboratories began shipping Hamilton C shell for OS/2.[23] It included both a csh clone and a set of Unix-like utilities. In 1992, Hamilton C shell was released for Windows NT.[24] The Windows version continues to be actively supported but the OS/2 version was discontinued in 2003.[24] An early 1990 quick reference[25] described the intent as "full compliance with the entire C shell language (except job control)" but with improvements to the language design and adaptation to the differences between Unix and a PC. The most important improvement was a top-down parser that allowed control structures to be nested or piped, something the original C shell could not support, given its ad hoc parser. Hamilton also added new language features including built-in and user-defined procedures, block-structured local variables and floating point arithmetic. Adaptation to a PC included support for the filename and other conventions on a PC and the use of threads instead of forks (which were not available under either OS/2 or Windows) to achieve parallelism, e.g., in setting up a pipeline.

See also

[edit]

References

[edit]
  1. ^ Zoulas, Christos (24 November 2016). "tcsh-6.20.00 is now available!". mx.gw.com. Archived from the original on 25 November 2016. Retrieved 24 November 2016.
  2. ^ Harley Hahn, Harley Hahn's Guide to Unix and Linux Archived 24 August 2019 at the Wayback Machine.
  3. ^ Berkeley Engineering Lab Notes, Volume 1, Issue 2, October 2001 Archived 9 July 2010 at the Wayback Machine.
  4. ^ An Introduction to the C shell Archived 13 July 2018 at the Wayback Machine by Bill Joy.
  5. ^ Ubuntu - Details of package csh. launchpad.net.
  6. ^ Debian - Details of package csh. tracker.debian.org.
  7. ^ Ubuntu - Details of package tcsh. launchpad.net.
  8. ^ Debian - Details of package tcsh. tracker.debian.org.
  9. ^ Ken Greer (3 October 1983). "C shell with command and filename recognition/completion". Newsgroupnet.sources. Retrieved 29 December 2010.
  10. ^ tcsh(1) man page. tcsh.
  11. ^ Fixes file in tcsh-17 June 2000.
  12. ^ Re: Late Bloomers Revisited USENET post to comp.lang.misc by Piercarlo "Peter" Grandi, Dept of CS, UCW Aberystwyth, UK, 17 December 1989.
  13. ^ Pronounced "bang, bang"
  14. ^ Troy, Douglas (1990). UNIX Systems. Computing Fundamentals. Benjamin/Cumming Publishing Company. p. 25.
  15. ^ Bourne, Stephen R. (October 1983). "The Unix Shell". BYTE. p. 187. Retrieved 30 January 2015.
  16. ^ The Insider's Guide To The Universe (PDF). Charles River Data Systems, Inc. 1983. p. 13.
  17. ^ IEEE Standard for Information Technology, Portable Operating System Interface (POSIX), Part 2: Shell and Utilities, Volume 2. IEEE Std 1003.2-1992, pp. 766-767. ISBN 1-55937-255-9.
  18. ^ Csh Programming Considered Harmful by Tom Christiansen
  19. ^ Top Ten Reasons not to use the C shell by Bruce Barnett
  20. ^ David Gries (1971). Compiler Construction for Digital Computers. John Wiley & Sons. ISBN 0-471-32776-X.
  21. ^ Bill Joy in Conversation with Brent Schlender, Churchill Club, Santa Clara, CA, 11 Feb 2009[usurped].
  22. ^ Holub, Allen (1986–1987). On Command: Writing a Unix-Like Shell for MS-DOS (Second ed.). M&T Books, Redwood City, CA. ISBN 0-934375-29-1.
  23. ^ Hamilton, Douglas. "Hamilton C shell Announcement" (PDF). IBM Personal Systems Developer (Summer 1989): 119–121. Retrieved 11 July 2020.
  24. ^ a b Hamilton, Nicole (5 March 2017). "Hamilton C shell for Windows Release Notes 5.2.g". Hamilton Laboratories, Redmond, WA. Retrieved 3 April 2018.
  25. ^ Hamilton C shell Quick Reference (PDF). Hamilton Laboratories, Wayland, MA. 1988–1990. Retrieved 11 July 2020.

Further reading

[edit]
[edit]
转念是什么意思 三维是什么 低烧吃什么 eason是什么意思 梦见生女孩是什么征兆
月经推迟挂什么科 脾胃湿热吃什么药好 beer是什么意思 恳谈会是什么意思 707是什么意思
雌二醇凝胶有什么作用 为什么明星都不戴黄金 感恩节为什么要吃火鸡 noxa20是什么药 canon是什么意思
乙肝1245阳性什么意思 5.20什么星座 何去何从是什么意思 水煮鱼片用什么鱼 为什么耳朵后面会臭
芊字五行属什么hcv8jop8ns5r.cn 什么是提示语hcv8jop6ns4r.cn 防中暑喝什么hcv8jop2ns7r.cn 夜字五行属什么bfb118.com 所向披靡什么意思dajiketang.com
张姓五行属什么aiwuzhiyu.com 宝宝睡觉头上出汗多是什么原因hcv8jop1ns2r.cn 自五行属什么cj623037.com 牙齿出血是什么病征兆hcv7jop5ns5r.cn 木行念什么hcv9jop1ns5r.cn
世界上牙齿最多的动物是什么hcv9jop4ns6r.cn 作息时间是什么意思hcv8jop9ns6r.cn 孩子结膜炎用什么眼药水hcv9jop0ns1r.cn 鹦鹉喜欢吃什么东西hcv7jop6ns1r.cn 知了叫什么hcv9jop6ns9r.cn
什么是天葬hcv8jop5ns5r.cn 尿激酶的作用及功效是什么hcv7jop9ns8r.cn 郑成功是什么朝代的adwl56.com 规培护士是什么意思hcv8jop1ns4r.cn 喉咙干是什么原因hcv7jop5ns1r.cn
百度