Article View: cn.comp.os.linux
Article #858Re: 初手问一个脚本的小问题
From: Jian Lee
Date: Sun, 28 Sep 2008 03:27
Date: Sun, 28 Sep 2008 03:27
210 lines
10173 bytes
10173 bytes
�е�Ǹ�⣬�����˽�Ҳ����̫��ϸ���������ת��ѧϰ��ʽ����������������ֲ� ҳ���Ҿ����ջ�dz�����Զೢ�ԡ���ʵlinux�Ĵ𰸺ܶ��doc���档 ���Ǻǣ�doc�������ǵ�ϵͳ�ϣ�ֻ��ϧ�ܶ�ʱ�����Ǻ����ˡ�Ҳ�ѹ֣�˭�� ���Ƕ���Ӣ�������أ�û�ķ�������ֿ���Щ������ϣ����һ�죬�������õ� ��Ӳ��û����ĸ��ֻ�з����֣�һ��Ŭ���ɣ��� yunhai <yunyousihaiAT@gmail.dotcom> writes: > лл����ѧϰ�¡��� > > On Sun, 28 Sep 2008 11:16:41 +0800, Jian Lee > <jian.li@turbolinux.com.cn> wrote: > >> yunhai <yunyousihaiAT@gmail.dotcom> writes: >> >>> On Sat, 27 Sep 2008 16:12:05 +0800, Jian Lee >>> <jian.li@turbolinux.com.cn> wrote: >>> >>>> >>>> �Ǻǣ����ÿ�������֪��Ҳ����̫ϸ�� >>>> >>>> ������һ�� "&"���ó����ں�̨���У���exec��ȫ��һ��� > �� >>> ��IDҲ����� >>>> ��ID��һ��ֻ�����ó���̨���У����ǿ��Բ��صȴ���� > �� >>> ����ܵõ� >>>> ��shell��ʾ�� >>>> >>> ��ֱ����terminal��ִ��exec opera &��opera��Ϊterminal���� > ��� >>> �������滻����ʲô��̣� >> �滻���� terminal >> >> exec ���÷��ܶ�ģ���ǰ�������ڼǵò�̫�壬exec��bash��һ > �������� >> �GNU��info� >> >> `exec' >> exec [-cl] [-a NAME] [COMMAND [ARGUMENTS]] >> If COMMAND is supplied, it replaces the shell without > creating a >> new process. If the `-l' option is supplied, the shell > places a >> dash at the beginning of the zeroth arg passed to COMMAND. > This >> is what the `login' program does. The `-c' option causes > COMMAND >> to be executed with an empty environment. If `-a' is > supplied, >> the shell passes NAME as the zeroth argument to COMMAND. > If no >> COMMAND is specified, redirections may be used to affect > the >> current shell environment. If there are no redirection > errors, the >> return status is zero; otherwise the return status is > non-zero. >> >> >> ���˸����ӣ����ں��档exec���˽�̶ȿ��Է�Ӧ���Ƕ�Unix��ѧ > �����̶ȣ��� >> �ǣ��һ����������ѧϰһ�¡� >> >> ------------------------------------ >> ��bash��ִ��exec�����������������浱ǰ��bash��̡���ˣ� > �����������⣺ >> >> $exec ls >> [logout] >> >> ��Ȼִ������һ�������term���ˣ��ǣ�exec�����ʲô���أ� >> >> �õġ����磬�ڲ���linux����У��Ѿ���һ��term�½����˺ܶ�� > ���������Ѿ�������������������������õ�һ��������ȥ��ȫ > �µ�bash�Ļ����Ϳ����������� >> $exec sh -l >> ���У�"-l"ѡ��ָ����sh(��bash)����login bash��ͬ�ij�ʼ���� >> ����˵��profile, ~/.bashrc���ļ��� >> �������Ǿ͵õ�һ��ȫ�µ�bash, ���Ҳ��������Ľ�̡� >> $ps ux >> ������ >> ... >> 1004 37233 pts/6 sh -l >> 1004 37237 pts/6 ps ux >> >> ��ʱ�����ǵ�½term���ֻ����ͨ������ssh����Ļ�����ȥ���� > ���ǾͿ����������� >> >> ���������ˡ� >> >> ��˵��һ���������ļ������� >> $cat <from >to 2>&1 >> >> �Ա��ļ�����0��1��2�����ض��������Ƕ��ᡣҲ����˵���� > bash֮�£�����ֻ����ͬʱ��3���ļ��������Ը����ļ�ͬʱ�� > �������в����أ� >> $exec 3> foobar >> $ls >&3 >> $exec 3>&- >> $exec 3< foobar >> $cat <&3 >> $exec 3<&- >> >> -cour-- >> >> ͨ��exec��"x<&-", "x>&-"����ϣ����Թر��ļ��� >> >> ���ֻ�Ƕ���дһЩ��ݵ��ļ��У���ôcat, echo �� "<", ">"�� >> ">>"����Ͼ��ˡ�Ϊʲô��Ҫ����Щ�鷳�أ�aha~~, ���ˣ��� >> ��һ��������������������ĺô������ڣ����е�ǰ�ļ���ƫ�� >> ָ�롣 >> >> #example: >> $exec 3< foo >> $read bar <&3 >> $echo $bar >> first_line_of_foo >> >> �������Ǿ��ܰ��ļ�"foo"�еĵ�һ�ж�������$bar���ˡ����ظ� > һ���������: >> $echo bar <&3 >> ���ܶ������������~ >> >> �������д��һ���ű�script1, ��Լ���ã��Ե�3�ļ����������� >> �ݣ�����һ������"<&"����ͨ��: >> $./script1 >> ���������script1���������ļ������? >> >> ========================================= >>> >>>> ִ��sh�ű��ǿ�һ��sh��̵ģ���ű��е�opera�ĸ���̾����� > �� >>> sh����ˡ� >>>> >>>> >>> ֱ����terminal��ִ��sh����õ�sh��ʾ�������ڽű��ﲻ�� > exec >>> ��ʱ����ps -e|grep sh�鿴��̣�û����sh�����sh��̵��� > ��ȥ >>> �ˣ� >>> >>> ������˼����������Ƚ϶ࡣ >> >> >> >>> >>>> yunhai <yunyousihaiAT@gmail.dotcom> writes: >>>> >>>>> On Sat, 27 Sep 2008 13:23:02 +0800, Jian Lee >>>>> <jian.li@turbolinux.com.cn> wrote: >>>>> >>>>>> �滻����exec����Ľ�̣��ٸ����ӣ� >>>>>> >>>>>> ��һ��terminal��������� >>>>>> # exec ls >>>>>> >>>>>> ����ʲô�ˣ��Dz���terminal���ڹر��ˣ�����Ĺ����ǣ� >>>>>> terminal���������ls��̣�ls����滻����ĸ���̣�Ҳ�� > �� >>> terminal�� >>>>>> �?terminal��̾Ͳ������ˡ�ls������ϣ��˳��ˣ����ڵ� > Ȼ >>> �ر��ˡ� >>>>>> >>>>>> ��һ�������ǿ��Կ������ ID����һ��terminal�� >>>>>> # echo $$ ; ���Կ�����ǰ��̵�ID >>>>>> # bash ; �����ڿ���ID��һ�������治һ���ˣ���Ϊ�������� > �� >>> һ���µĽ�� >>>>>> # echo $$ ; ��ס��������صļҳ�ID�ţ����Ϊ ���ס� >>>>>> # exec sh >>>>>> # echo $$ ; ���ﷵ�صĽ��͡��ס���һ��ġ� >>>>> >>>>> лл��Ľ��͡� >>>>> >>>>> ����һЩ�����ġ� >>>>> ��exec���滻��̣�������exec������������&�Ļ�����ôʵ > �� >>> Ч���Dz��Ǿ� >>>>> ����exec�����һ����߶���ʹ���µĽ��ID�������� >>> terminal��ִ��exec >>>>> opera &��opera &�� >>>>> >>>>> �������������ڽű���ʹ��exec���������ֱ����terminal��ִ > �� >>> exec���е㲻 >>>>> һ��ֱ��ִ��exec opera֮�ر�opera��terminal����Ҳ > �� >>> ��֮�رգ����� >>>>> ���ڽű����õĻ����ر�opera��ԭ����terminal����رգ��� > �� >>> IDҲ���䡣���� >>>>> Ϊʲô�أ���ִ�нű���ʱ���¿�һ��bash�𣿿����ڽű� > �� >>> ����exec���� >>>>> ����Ҳû�з��ֶ��һ��bash�� >>>>> >>> >>> -- >>> Using Opera's revolutionary e-mail client: >>> http://www.opera.com/mail/ > > > > -- > Using Opera's revolutionary e-mail client: > http://www.opera.com/mail/
Technical Details
Message-ID:
<r6756jcq.fsf@dev3-168.dev.cn.tlan>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.neu.edu.cn!news.cn99.com!not-for-mailReferences:
<op.uhy15abv5u2pxgyh@yunyousihai.org> <877i9283id.fsf@home.emacser.com> <op.uhy709075u2pxgyh@yunyousihai.org> <7i91dlnk.fsf@dev3-168.dev.cn.tlan> <op.uh2v82dj5u2pxgyh@yunyousihai.org> <abdukvrd.fsf@dev3-168.dev.cn.tlan> <op.uh4pv3dd5u2pxgyh@yunyousihai.org> <d4iqypm2.fsf@dev3-168.dev.cn.tlan> <op.uh4s78hd5u2pxgyh@yunyousihai.org> <vdwh6jty.fsf@dev3-168.dev.cn.tlan> <op.uh58v2j85u2pxgyh@yunyousihai.org>Show Full Headers
Complete Article Headers
X-Google-Thread: 10b277,8e750585191b5336 X-Google-Attributes: gid10b277,domainid0,public,usenet X-Google-Language: Chinese,GB Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.neu.edu.cn!news.cn99.com!not-for-mail From: Jian Lee <jian.li@turbolinux.com.cn> ( 闲云 ) Newsgroups: cn.comp.os.linux Subject: Re: 初手问一个脚本的小问题 Date: Sun, 28 Sep 2008 11:27:01 +0800 Organization: Bentium Ltd. (CN99) Lines: 210 Message-ID: <r6756jcq.fsf@dev3-168.dev.cn.tlan> References: <op.uhy15abv5u2pxgyh@yunyousihai.org> <877i9283id.fsf@home.emacser.com> <op.uhy709075u2pxgyh@yunyousihai.org> <7i91dlnk.fsf@dev3-168.dev.cn.tlan> <op.uh2v82dj5u2pxgyh@yunyousihai.org> <abdukvrd.fsf@dev3-168.dev.cn.tlan> <op.uh4pv3dd5u2pxgyh@yunyousihai.org> <d4iqypm2.fsf@dev3-168.dev.cn.tlan> <op.uh4s78hd5u2pxgyh@yunyousihai.org> <vdwh6jty.fsf@dev3-168.dev.cn.tlan> <op.uh58v2j85u2pxgyh@yunyousihai.org> NNTP-Posting-Host: yy-132-18-a8.bta.net.cn Mime-Version: 1.0 Content-Type: text/plain; charset=gb2312 Content-Transfer-Encoding: 8bit X-Trace: news.cn99.com 1222572419 18845 202.108.132.18 (28 Sep 2008 03:26:59 GMT) X-Complaints-To: usenet@news.cn99.com NNTP-Posting-Date: Sun, 28 Sep 2008 03:26:59 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) Cancel-Lock: sha1:68s4CoDtyBD6MVhg/nkbCUZfKHo=