圣女是什么生肖| 白带是什么样子| 2003年的羊是什么命| 内向什么意思| 月亮星座是什么| 尿路感染看什么科室| 性格内敛是什么意思| 什么奶粉跟母乳一个味| 肌无力是什么原因引起的| 传字五行属什么| 额头凉凉的是什么原因| 魔芋是什么植物| 结婚20年是什么婚姻| 自怨自艾是什么意思| 吃什么水果对皮肤好又美白| apm是什么品牌| ex是什么的缩写| 杨字五行属什么| 三焦是什么器官| 什么地望着| 硼砂是什么| 基础油是什么油| 梅核气是什么症状| 情调是什么意思| 末次月经是什么意思| 壬水代表什么| 壁是什么意思| 三更是什么生肖| 梦见给别人剪头发是什么意思| 为难的难是什么意思| omega什么牌子手表| 10月1是什么星座| 破军星是什么意思| 脸发红是什么原因| 甲亢吃什么药好得快| 舌头边上有锯齿状是什么原因| 怀孕吃什么会流产| 老人流口水是什么原因引起的| 黄色裤子搭配什么颜色上衣| 属蛇的五行属什么| 嘴唇上长痣代表什么| 漱口杯什么材质好| 塞浦路斯说什么语言| 心率过快吃什么药最好| 紫外线过敏吃什么药| 鹅口疮有什么症状| longines是什么牌子| 面瘫去医院挂什么科| 1885年属什么生肖| 血脂高有什么症状| 大拇指指甲凹凸不平是什么原因| 虫草花是什么| 9点多是什么时辰| 口苦吃什么药最好| 因加一笔是什么字| 人为什么会长白头发| 142是什么意思| 下午4点是什么时辰| 黄豆可以和什么一起打豆浆| 小龙虾吃什么| 黄水疮用什么药膏最快| 河豚有毒为什么还吃| 706代血浆又叫什么| 吃什么代谢快有助于减肥| 爷爷的兄弟叫什么| 驼鸟吃什么食物| 狐假虎威是什么意思| 由来是什么意思| 排浊是什么意思| 猪肚炖什么| ad是什么的缩写| 猛虎下山是什么意思| 骨龄什么时候闭合| 吃豆腐有什么好处| 大肠杆菌属于什么菌| 阴虚内热是什么意思| 头晕目眩吃什么药| 双脚麻木是什么病的前兆| gmp什么意思| 过敏性荨麻疹吃什么药| 维生素b12治什么病| 黄精什么人不能吃| 血常规白细胞偏高是什么原因| 5月17日是什么星座| 两胸中间疼是什么原因| 白斑是什么原因引起的| 卡他症状是什么意思| 急性肠胃炎吃什么食物| 什么原因导致脱发| 尿胆红素2十是什么意思| 什么都想要| 13太保是什么意思| lu是什么单位| 官方翻新机是什么意思| 仙逝是什么意思| 四大美女是什么生肖| 孩子急性肠胃炎吃什么药| 五险一金指什么| 什么食物含硒量最高| 情绪什么意思| 保育费是什么意思| 文科女生学什么专业好| 5月31号是什么星座| 甲状腺功能挂什么科| 职业规划是什么| 帕金森吃什么药最好| 心脏房颤吃什么药好| nt检查需要注意什么| 补办身份证需要什么手续| 后背容易出汗是什么原因| 儿童便秘吃什么药| 我操是什么意思| 床上出现蜈蚣什么原因| 被利用的信任是什么歌| 黄芪的作用是什么| 低血压有什么症状| 手麻吃什么药| 腮边长痘是什么原因| 囊中之物是什么意思| 一毛不拔指什么生肖| 为什么冰箱冷藏室会结冰| 血糖仪h1是什么意思| 蕾丝是什么| 流鼻涕吃什么药最管用| 油腔滑调指什么生肖| 孕妇缺铁吃什么| 蒸馏水是什么| 怀孕尿液是什么颜色| es什么意思| 电脑什么时候发明的| 肾结石挂什么科| 肚脐下三寸是什么位置| 马铃薯什么时候传入中国| 带沉香手串有什么好处| 十月是什么星座| diqua是什么牌子| 晚上20点是什么时辰| 风对什么| 金乐什么字| grader是什么意思| 矢车菊在中国叫什么名| 7月24日是什么星座| 稀料对人体有什么危害| 反将一军什么意思| rdw是什么意思| 丁克族是什么意思| 老放屁是什么原因| 喘粗气是什么原因| 张良属什么生肖| 支付宝账户是什么| 涉三什么意思| 郫县豆瓣酱能做什么菜| 为什么七星瓢虫是益虫| 心阳不足吃什么中成药| 子宫肌壁回声不均匀是什么意思| 反乌托邦什么意思| 血液粘稠是什么原因| 夜里2点到3点醒什么原因| 五行什么生木| 梦见抓甲鱼是什么意思| 什么样的大象| 每天放很多屁是什么原因| 80年出生属什么生肖| 不想吃油腻的东西是什么原因| 月子吃什么| chuck是什么意思| 肝寒吃什么中成药| 为什么会梦到蛇| 眼睛模糊是什么原因引起的| 六小龄童的真名叫什么| 吃什么可以增强硬度| 后脑勺胀痛什么原因| 前胸后背长痘痘是什么原因| 航母舰长是什么级别| 塔罗牌逆位是什么意思| 手心发烧是什么原因| 红颜知己是什么意思| 八面玲珑什么生肖| 烫伤擦什么药膏| 什么是肝阳上亢| 五子登科是什么意思| 家庭主妇是什么意思| 白里透红的透是什么意思| 人中短代表什么| 治愈是什么意思| 鱼刺卡喉咙挂什么科| 谷氨酰基转移酶低是什么原因| 随心所欲的欲什么意思| 鱼肝油是什么| ms是什么| 狗为什么喜欢吃屎| 自行车什么牌子好| 马杀鸡是什么意思| 尾盘拉升意味着什么| 7一9点是什么时辰| 6.5号是什么星座| 基因突变什么意思| 西瓜什么时候传入中国| 莲子吃了有什么好处| 黑蚂蚁泡酒有什么功效| 卖是什么意思| 美帝是什么意思| 正局级什么级别| 食禄是什么意思| 做健身教练有什么要求| 载脂蛋白b偏高是什么意思| 梦到吃肉是什么意思周公解梦| 60大寿送什么礼物| 什么牌子皮带结实耐用| 兵马未动粮草先行是什么意思| 10月24日什么星座| 双源ct主要检查什么| 小便有点红是什么原因| 女人安全期是什么时候| 台球杆什么牌子的好| 庚申五行属什么| 水当当是什么意思| 木薯粉是什么| 土中金是什么数字| 头孢有什么作用| 话赶话是什么意思| 伊朗是什么教派| 频繁放屁是什么原因| 猪头三是什么意思| 活血化瘀吃什么药| 三尖瓣轻度反流说明什么| 命运是什么意思| 三叉神经疼吃什么药| 股骨头坏死有什么症状| 白芍有什么功效和作用| biubiubiu是什么意思| 为什么来月经会拉肚子| 血少一撇念什么| 经常拉肚子吃什么药好| 湿疹什么症状| 奶奶的弟弟叫什么| 女性吃金蝉有什么好处| 头晕应该挂什么科| 日什么月什么| 急性胃炎吃什么药好| 反吟是什么意思| 九夫痣是什么意思| 活好的女人有什么表现| 点睛之笔是什么意思| 属猴的守护神是什么菩萨| 台湾什么时候回归的| 为什么一躺下就鼻塞| 智齿发炎吃什么| 岁寒三友是什么意思| 高定是什么意思| 双手脱皮是什么原因引起的| 麻是什么原因| 猪八戒原名叫什么| 肚子硬硬的是什么原因| 10.30是什么星座| 股骨头疼痛吃什么药| 欲情故纵是什么意思| 痔疮术后吃什么恢复快| 人质是什么意思| 卵黄囊偏大是什么原因| 1月份是什么星座的人| 马叉虫是什么意思| 心口疼痛是什么原因| 开放式耳机是什么意思| 百度

守望先锋新英雄?演员特里克鲁斯暗示E3有惊喜

百度   另一家券商固定收益分析师称,最近同业存单的价格下降得比较多,所以对于债基基金经理来讲,配存单和短债的收益率差别不大,所以转配短债也可以。

In computing, redirection is a form of interprocess communication, and is a function common to most command-line interpreters, including the various Unix shells that can redirect standard streams to user-specified locations. The concept of redirection is quite old, dating back to the earliest operating systems (OS).[citation needed] A discussion of the design goals for redirection can be found already in the 1971 description of the input-output subsystem of the Multics OS.[1] However, prior to the introduction of UNIX OS with its "pipes", redirection in operating systems was hard or even impossible to do.[2]

The standard streams for input, output, and error

In Unix-like operating systems, programs do redirection with the dup2(2) system call, or its less-flexible but higher-level stdio analogues, freopen(3) and popen(3).[3]

Redirecting standard input and standard output

edit

Redirection is usually implemented by placing certain characters between commands.

Basic

edit

Typically, the syntax of these characters is as follows, using < to redirect input, and > to redirect output. command > file1 executes command, placing the output in file1, as opposed to displaying it at the terminal, which is the usual destination for standard output. This will clobber any existing data in file1.

Using command < file1 executes command, with file1 as the source of input, as opposed to the keyboard, which is the usual source for standard input.

command < infile > outfile combines the two capabilities: command reads from infile and writes to outfile

Variants

edit

To append output to the end of the file, rather than clobbering it, the >> operator is used: command1 >> file1.

To read from a stream literal (an inline file, passed to the standard input), one can use a here document, using the << operator:

$ tr a-z A-Z << END_TEXT
> one two three
> uno dos tres
> END_TEXT
ONE TWO THREE
UNO DOS TRES

To read from a string, one can use a here string, using the <<< operator: tr a-z A-Z <<< "one two three", or:

$ NUMBERS="one two three"
$ tr a-z A-Z <<< "$NUMBERS"
ONE TWO THREE

Piping

edit
 
A pipeline of three programs run on a text terminal

Programs can be run together such that one program reads the output from another with no need for an explicit intermediate file. command1 | command2 executes command1, using its output as the input for command2 (commonly called piping, with the "|" character being known as the "pipe").

The two programs performing the commands may run in parallel with the only storage space being working buffers (Linux allows up to 64K for each buffer) plus whatever work space each command's processing requires. For example, a "sort" command is unable to produce any output until all input records have been read, as the very last record received just might turn out to be first in sorted order. Dr. Alexia Massalin's experimental operating system, Synthesis, would adjust the priority of each task as they ran according to the fullness of their input and output buffers.[4]

This produces the same end result as using two redirects and a temporary file, as in:

$ command1 > tempfile
$ command2 < tempfile
$ rm tempfile

But here, command2 does not start executing until command1 has finished, and a sufficiently large scratch file is required to hold the intermediate results as well as whatever work space each task required. As an example, although DOS allows the "pipe" syntax, it employs this second approach. Thus, suppose some long-running program "Worker" produces various messages as it works, and that a second program, TimeStamp copies each record from stdin to stdout, prefixed by the system's date and time when the record is received. A sequence such as Worker | TimeStamp > LogFile.txt would produce timestamps only when Worker had finished, merely showing how swiftly its output file could be read and written.

A good example for command piping is combining echo with another command to achieve something interactive in a non-interactive shell, e.g. echo -e 'user\npass' | ftp localhost. This runs the ftp client with input user, press return, then pass.

In casual use, the initial step of a pipeline is often cat or echo, reading from a file or string. This can often be replaced by input indirection or a here string, and use of cat and piping rather than input redirection is known as useless use of cat. For example, the following commands:

$ cat infile | command
$ echo $string | command
$ echo -e 'user\npass' | ftp localhost

can be replaced by:

$ command < infile
$ command <<< $string
$ ftp localhost <<< $'user\npass'

As echo is often a shell-internal command, its use is not as criticized as cat, which is an external command.

Redirecting to and from the standard file handles

edit

In Unix shells derived from the original Bourne shell, the first two actions can be further modified by placing a number (the file descriptor) immediately before the character; this will affect which stream is used for the redirection.[5] The Unix standard I/O streams are:[6]

Handle Name Description
0 stdin Standard input
1 stdout Standard output
2 stderr Standard error

For example, command 2> file1 executes command, directing the standard error stream to file1.

In shells derived from csh (the C shell), the syntax instead appends the & (ampersand) character to the redirect characters, thus achieving a similar result. The reason for this is to distinguish between a file named '1' and stdout, i.e. cat file 2>1 vs cat file 2>&1. In the first case, stderr is redirected to a file named '1' and in the second, stderr is redirected to stdout.

Another useful capability is to redirect one standard file handle to another. The most popular variation is to merge standard error into standard output so error messages can be processed together with (or alternately to) the usual output. For example, find / -name .profile > results 2>&1 will try to find all files named .profile. Executed without redirection, it will output hits to stdout and errors (e.g. for lack of privilege to traverse protected directories) to stderr. If standard output is directed to file results, error messages appear on the console. To see both hits and error messages in file results, merge stderr (handle 2) into stdout (handle 1) using 2>&1.

If the merged output is to be piped into another program, the file merge sequence 2>&1 must precede the pipe symbol, thus, find / -name .profile 2>&1 | less

A simplified but non-POSIX conforming form of the command, command > file 2>&1 is (not available in Bourne Shell prior to version 4, final release, or in the standard shell Debian Almquist shell used in Debian/Ubuntu): command &>file or command >&file.

It is possible to use 2>&1 before ">" but the result is commonly misunderstood. The rule is that any redirection sets the handle to the output stream independently. So "2>&1" sets handle 2 to whatever handle 1 points to, which at that point usually is stdout. Then ">" redirects handle 1 to something else, e.g. a file, but it does not change handle 2, which still points to stdout.

In the following example, standard output is written to file, but errors are redirected from stderr to stdout, i.e. sent to the screen: command 2>&1 > file.

To write both errors and standard output to file, the order should be reversed. Standard output would first be redirected to the file, then stderr would additionally be redirected to the stdout handle that has already been changed to point at the file: command > file 2>&1.

Chained pipelines

edit

The redirection and piping tokens can be chained together to create complex commands. For example, sort infile | uniq -c | sort -n > outfile sorts the lines of infile in lexicographical order, writes unique lines prefixed by the number of occurrences, sorts the resultant output numerically, and places the final output in outfile.[7] This type of construction is used very commonly in shell scripts and batch files.

Redirect to multiple outputs

edit

The standard command tee can redirect output from a command to several destinations:ls -lrt | tee xyz. This directs the file list output to both standard output and the file xyz.

See also

edit

References

edit
  1. ^ Feiertag & Organick 1972.
  2. ^ Kernighan & Morgan 1982, p. 780, Input/output redirection.
  3. ^ The GNU C Library Reference Manual for version 2.38 gnu.org
  4. ^ "KHB: Synthesis: An Efficient Implementation of Fundamental Operating Systems Services". lwn.net.
  5. ^ Nozaki, Roberto (April 21, 2022). "How to redirect shell command output". www.redhat.com.
  6. ^ "Redirections (Bash Reference Manual)". www.gnu.org.
  7. ^ "Piping and Redirecting Output in the Linux Terminal". Linux.org.

Sources

edit
edit
龙代表什么数字 相生相克是什么意思 又双叒叕念什么啥意思 缘分使然是什么意思 生理期为什么不能拔牙
糖类抗原125偏高说明什么 42年属什么生肖 仕女图是什么意思 胃反流有什么症状 道听途说什么意思
何辅堂是什么电视剧 籽料是什么意思 益生菌吃了有什么好处 站台是什么意思 六月十六什么星座
孕妇吃什么蔬菜对胎儿好 恶露是什么 涧是什么意思 三个毛念什么 婚检是什么
属鼠的贵人是什么属相hcv9jop8ns2r.cn 沐沐是什么意思hcv8jop6ns9r.cn 喝什么对嗓子好hcv8jop2ns9r.cn 膀胱炎挂什么科hcv7jop9ns8r.cn 白羊跟什么星座最配hcv8jop2ns5r.cn
无名指和食指一样长代表什么hcv8jop3ns9r.cn 刚刚怀孕有什么症状hcv7jop7ns4r.cn 梦见很多棺材是什么征兆hcv8jop0ns3r.cn 什么少年hcv7jop9ns0r.cn 润物细无声是什么意思hcv8jop8ns6r.cn
maxco是什么牌子hcv8jop8ns7r.cn 白砂糖和冰糖有什么区别hcv8jop0ns7r.cn 暂时无法接通是什么意思hcv9jop6ns7r.cn 什么天喜地hkuteam.com 抑制剂是什么hcv9jop4ns5r.cn
偏光是什么意思hcv7jop6ns0r.cn 久坐腰疼是什么原因hcv8jop3ns5r.cn 鸡蛋清敷脸有什么好处和坏处liaochangning.com 上传下达什么意思bjhyzcsm.com 什么龙什么虎hcv8jop7ns8r.cn
百度