Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the basic syntax of Csh

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "how to understand the basic grammar of Csh". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

In * unix system, the commonly used shell is sh,bash,csh/tcsh, ksh.

Sh comes from systemV's Unix, which is the shell of traditional Unix. Until now, many system administrators still like to use sh.

Bash comes from BSD Unix, and its syntax is very similar to the C language, so it is usually preferred by developers with a programming background of Cpicard Cure +.

Ksh is an extension of sh and absorbs some useful features of csh, but since the license of ksh is AT&T, there have been many open source versions of ksh, such as mksh,pdksh and so on.

Bash is the default shell in many current Linux distributions, combining many of the advantages of other shell.

The following describes some basic syntax of csh (performing a csh switch from a sh environment to a csh environment):

1) variable

Define the local variable x through set, use the value of variable x through $x or ${x}, $% x represents the length of the value of the variable, and $? X to determine whether variable x is set, if set, it is 1, otherwise it is 0.

The code is as follows:

Set x = 5

Echo $x

Echo ${x} kg

Echo $x

Definition of a global variable setenv v value this variable will be inherited by all child shell derived from this shell.

$represents the PID of the current process, $status or $? Indicates the exit status.

2) Array

Define the array myarr, access the values in the array through $myarr [index], and note that index starts at 1. Access all elements of the array through $myarr or $myarr [*]. Use $# myarr to see the number of elements.

The code is as follows:

Set myarr = (str1, str2,str3)

Echo $myarr [2]

Echo $myarr

Echo $myarr [*]

3) Command replacement

The command is executed by set x = `cmd`, and the result is assigned to the variable.

The code is as follows:

Set d = `date`

Echo $d

Echo $d [6]-$d [2]-$d [3]

4) Command line arguments

Access command-line arguments through $argv [1], $argv [2], or $1 dint 2. The number of command line arguments is $# argv.

5) metacharacters of file name extension

You can only use?, *, [abc], [Amurc].

6) IO redirection and pipelin

Redirect the output of the command to a file of >.

Redirect the output of the command and append it to the file as > >.

Redirect the input of the command to the file / dev/tty) > & errors.

Redirect command output and error output (cmd > goodstuff) > & badstuff, respectively.

Redirect the output of the command and error information to a file cmd > & file.

Send the output of the command to another command, cmd | cmd.

Send the output and error information of the command to another command cmd | & cmd through the pipeline.

The conditional statement is cmd & & cmd or cmd | | cmd.

Command testfile

% set noclobber

Echo "test set noclobber" > testfile

Testfile: File exists.

Echo "test set noclobber" >! Testfile

%

Example 2:

The code is as follows:

% set noclobber

Cat / etc/passwd > > nopass

Nopass: No such file or directory

Cat / etc/passwd > >! Nopass

%

This is the end of "how to understand the basic Grammar of Csh". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 210

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report