原帖由 waker 于 2006-4-20 08:04 发表
3.使用coprocess(ksh)
( echo "$a" |&)
read -p b
in kornshell try
echo "$a"|read b
echo $b
原帖由 waker 于 2006-4-20 08:19 发表
Q1中
A: 这里的简单命令和bash参考手册里的含义相同,形式上一般是:命令的名称加上它的参数+赋值操作+IO重定向描述
从上面看
var=value不是一个简单命令,而是上面的第二部分
原帖由 waker 于 2006-4-20 10:10 发表
这也就是为什么ps不能找到正在运行的脚本的名字的原因了。
或许有另一种解释
如果找不到,不妨在脚本上加入 #!试试
这个可以从manpage中找到解释
If this execution fails because the file is not ...
...
Commands.
A simple-command is a list of variable assignments (see VariableAssignments below) or a sequence of blank separated words which may be preceded by a list of variable assignments (see Environment below). The first word specifies the name of the command to be executed. Except as specified below, the remaining words are passed as arguments to the invoked command. ...
...
A command is either a simple-command or one of the following. Unless otherwise stated, the value returned by a command is that of the last simple-command executed in the command.
for vname [ in word . . . ] ;do list ;done
Each time a for command is executed, vname is set to the next word taken from the in word list. If in word . . . is omitted, then the for command executes the do list once for each positional parameter that is set starting from 1 (see ParameterExpansion below). Execution ends when there are no more words in the list.
for (( [ expr1 ] ; [ expr2 ] ; [ expr3 ] )) ;do list ;done
The arithmetic expression expr1 is evaluated first (see ArithmeticEvaluation below). The arithmetic expression expr2 is repeatedly evaluated until it evaluates to zero and when non-zero, list is executed and the arithmetic expression expr3 evaluated. If any expression is omitted, then it behaves as if it evaluated to 1.
select vname [ in word . . . ] ;do list ;done
A select command prints on standard error (file descriptor 2) the set of words, each preceded by a number. If in word . . . is omitted, then the positional parameters starting from 1 are used instead (see ParameterExpansion below). The PS3 prompt is printed and a line is read from the standard input. If this line consists of the number of one of the listed words, then the value of the variable vname is set to the word corresponding to this number. If this line is empty, the selection list is printed again. Otherwise the value of the variable vname is set to null. The contents of the line read from standard input is saved in the variable REPLY. The list is executed for each selection until a break or end-of-file is encountered. If the REPLY variable is set to null by the execution of list, then the selection list is printed before displaying the PS3 prompt for the next selection.
case word in [ [ ( ]pattern [ | pattern ] . . . ) list ;; ] . . . esac
A case command executes the list associated with the first pattern that matches word. The form of the patterns is the same as that used for file-name generation (see FileNameGeneration below). The ;; operator causes execution of case to terminate. If ;& is used in place of ;; the next subsequent list, if any, is executed.
if list ;then list [ elif list ;then list ] . . . [ ;else list ] ;fi
The list following if is executed and, if it returns a zero exit status, the list following the first then is executed. Otherwise, the list following elif is executed and, if its value is zero, the list following the next then is executed. Failing each successive elif list , the else list is executed. If the if list has non-zero exit status and there is no else list, then the if command returns a zero exit status.
while list ;do list ;done
until list ;do list ;done
A while command repeatedly executes the while list and, if the exit status of the last command in the list is zero, executes the do list; otherwise the loop terminates. If no commands in the do list are executed, then the while command returns a zero exit status; until may be used in place of while to negate the loop termination test.
((expression ))
The expression is evaluated using the rules for arithmetic evaluation described below. If the value of the arithmetic expression is non-zero, the exit status is 0, otherwise the exit status is 1.
(list )
Execute list in a separate environment. Note, that if two adjacent open parentheses are needed for nesting, a space must be inserted to avoid evaluation as an arithmetic command as described above.
{ list ;}
list is simply executed. Note that unlike the metacharacters ( and ), { and } are reserved words and must occur at the beginning of a line or after a ; in order to be recognized.
[[ expression ]]
Evaluates expression and returns a zero exit status when expression is true. See ConditionalExpressions below, for a description of expression.
function varname { list ;}
varname () { list ;}
Define a function which is referenced by varname. A function whose varname contains a . is called a discipline function and the portion of the varname preceding the last . must refer to an existing variable. The body of the function is the list of commands between { and }. A function defined with the function varname syntax can also be used as an argument to the . special built-in command to get the equivalent behavior as if the varname () syntax were used to define it. (See Functions below.)
time [ pipeline ]
If pipeline is omitted the user and system time for the current shell and completed child processes is printed on standard error. Otherwise, pipeline is executed and the elapsed time as well as the user and system time are printed on standard error.
The following reserved words are recognized as reserved only when they are the first word of a command and are not quoted:
if then else elif fi case esac for while until do done { } function select time [[ ]] !
...
...
Simple Commands
If a simple command has been recognized, the shell performs the following actions:
1. Leading words of the form "name=value" are stripped off and assigned to the environment of the simple com-
mand. Redirection operators and their arguments (as described below) are stripped off and saved for pro-
cessing.
2. The remaining words are expanded as described in the section called "Expansions", and the first remaining
word is considered the command name and the command is located. The remaining words are considered the
arguments of the command. If no command name resulted, then the "name=value" variable assignments recog-
nized in item 1 affect the current shell.
...
我的看法:无论如何,脚本不作为单独的进程运行,单独运行的是脚本的解释器进程。
原帖由 woodie 于 2006-4-20 20:07 发表
所以,我认为赋值可以作为命令这一点应该没有问题,至于是否是内部命令则可以商榷。不过就其表现,把它归入builtin命令一类,也无太大不妥。 ...
原帖由 woodie 于 2006-4-20 19:38 发表
...
* shell脚本可以不在首行指定解释器,缺省的解释器/bin/sh会被用来解释、执行它。这一点你说的是对的,....
原帖由 woodie 于 2006-4-21 15:12 发表
... T3.脚本在实际应用中不能作为系统进程调度的一个基本单元,那么认为它可以作为进程又有何益处呢?
原帖由 大蚂蚁 于 2006-4-22 03:21 发表
..
但是,我还有个疑问:eval属于build in还是?
原帖由 r2007 于 2006-4-20 21:46 发表
可以看出var=val,在不同的上下文中有不同的解释。如果单独出现则是普通的赋值语句,如果有其他命令,则是用来定义环境变量的,且不影响当前的环境。 ...
原帖由 Cygnus 于 2006-6-12 05:38 发表
Acutally, environment variables are a big topic. For example, do you think the following two lines
can be the same:
echo a=1 b
a=1 echo b
原帖由 waker 于 2006-6-12 16:32 发表
[waker@proxy dd3]$ echo a=1 b
b
[waker@proxy dd3]$ echo a=1 b
a=1 b
原帖由 waker 于 2006-6-12 17:27 发表
[code]
If the -k option is set (see the set builtin command below), then all
parameter assignments are placed in the environment for a command, not
just those that precede ...
原帖由 r2007 于 2006-6-12 17:30 发表
确实如此,看来该补课了。
原帖由 waker 于 2006-6-12 16:32 发表
在bash中,它们一样不一样取决于你的喜好
[code]
原帖由 woodie 于 2006-6-12 15:40 发表
... 但你知道在linux下这通常是/bin/bash的一个符号链接, ...
原帖由 Cygnus 于 2006-6-13 08:31 发表
You got it.
Another quick question for all of you:
1. Can you list all links (hard and soft) you know about shells.
2. What is the purpose of these links?
原帖由 r2007 于 2006-6-13 08:50 发表
It seems you think waker got it. I don't think just a "-k" option is the all you call a big topic about the environment.
Can you tell us more about environment variables?
原帖由 Cygnus 于 2006-6-13 08:31 发表
You got it.
Another quick question for all of you:
1. Can you list all links (hard and soft) you know about shells.
2. What is the purpose of these links?
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |