LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
楼主: johnny_jiang

$@和$*的问题!!!

[复制链接]
 楼主| 发表于 2006-2-22 08:43:10 | 显示全部楼层
Post by yongjian
不是。这是完全不同的。当你输入变量值时,必须依照shell的语法规定,即如果有IFS分隔在变量值中出现,必须由单/双引号括起。当赋值完成之后,变量得到指向数值的内存地址。转递时,新变量得到一个拷贝,和原来的一模一样。当打印时,bash根据命令行规则分隔和去处单/双引。



真的是多谢yongjian兄这一路的帮助.:thank
另外,yongjian兄能否推荐一些关于这些基础知识方面的书籍或者电子文档,小弟希望能够将基础打好,先谢了.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-2-22 10:51:58 | 显示全部楼层
又要麻烦yongjian大侠了,又有一个概念性的问题想请教您.



  1. bash# alias if='ls -l'

  2. bash# if

复制代码


这样一来,将显示当前目录的内容,命令解释符合了命令优先级,既是

1.别名
2.关键字
3.函数
4.builtin
5.可执行文件

不过如果根据home_king的'Bash命令行处理[详解] '一贴中的说明,在第二步的时候不就应该对开放关键字 if 进行分析了吗,而别名的解析却是在第三步.所以小弟对此感觉好象有点矛盾,难以理解
回复 支持 反对

使用道具 举报

发表于 2006-2-22 12:05:42 | 显示全部楼层
这个我还没有想过,不过试了一下,果如你说。别名的处理要在检查keyword之前。google看了一下关于POSIX标准的命令执行顺序,alias是第一位的,所以我想可能home_king兄的2,3要调一调的吧。这里附上POSIX command execution sequence:

  An overview of the POSIX command execution sequence, which
covers (in general order of processing):

1) aliases

2) reserved keywords (what look like programming constructs):
  ! { } case do done elif else esac fi for if in then until while

3) special built-ins:
  break : continue . eval exec exit export readonly
  return set shift times trap unset

4) functions

5) regular built-ins:
  alias bg cd command false fc fg getopts jobs kill newgrp
  pwd read true umask unalias wait

Aliases
-------

  - aliases can be defined to override anything from special
    built-ins on down.  Technically, they can be *defined*
    to override reserved keywords, but this substitution will
    not be allowed at processing time (unlike standard bash
    behavior), so you might as well just say you can't redefine
    keywords.

  - to override normal alias processing, put the alias in quotes,
    or backslash escape it:


  $ set                runs "set"
  $ alias set=ls
  $ set                runs "ls"
  $ "set"              runs "set"
  $ \set               also runs "set"

Special versus regular built-ins
------- ------ ------- ---------

  The differences between special and regular built-ins:

  1) syntax errors in special built-ins *may* cause a shell to abort,
     while errors in a regular built-in shall not

  2) variable assignments specified with specials shall remain
     in effect after the special completes, but not so with
     regulars.

So you have the difference between, say

  $ VAR=value set      (VAR available further on)
  $ VAR=value jobs     (VAR *not* available further on)

And the other big difference is, clearly, that you can define
a function to override a regular, but not a special, built-in.

Functions
---------

  POSIX standard:

  f () {
   ....
  }

  "When a function is executed, it shall have the syntax-error
   and variable assignment properties described for special
   built-in utilities ...".  Yuck.

The "command" command
--- --------- -------

  Putting the "command" command in front of a command does
a number of things:

  1) if the command is an alias, it prevents alias expansion

  2)

  "If the command_name is the same as the name of one of the
special built-ins, the special properties in the enumerated
list [above] shall not occur.  In every other respect, if
command_name is not the name of a function, the effect of
"command" (with no options) shall be the same as omitting
"command".

  3) And, as you see above, it suppresses function lookup,
     so you can override *regular* shell builtins with functions
     of the same name, so you could override the built-in cd
     command with a function of the same name:

  cd () {
     .....
     command cd ...
     .....
  }

附上关于builtin的注释:
The different categories of "built-in" commands:

reserved keywords:
  ! { } case do done elif else esca fi for if in then until while

special builtins:
  break : continue . eval exec exit export readonly
  return set shift times trap unset

regular builtins:
  alias bg cd command false fc fg getopts jobs kill newgrp
  pwd read true umask unalias wait
回复 支持 反对

使用道具 举报

发表于 2006-2-22 12:21:12 | 显示全部楼层
Post by johnny_jiang
真的是多谢yongjian兄这一路的帮助.:thank
另外,yongjian兄能否推荐一些关于这些基础知识方面的书籍或者电子文档,小弟希望能够将基础打好,先谢了.

tldp.org上Mendel Cooper的大作Advanced Bash Scripting是我首推的。Oreilly Unix CD bookshelf中sed/awk第二版也是很好的书。如果你没有,到图书馆版有帖子,贴上你的email我可以发给你。还有几本象Learning the bash shell, unix/linux shell编程指南,master regular expression, Effective AWK programming等也非常值得看。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-2-22 13:37:29 | 显示全部楼层
Post by yongjian
tldp.org上Mendel Cooper的大作Advanced Bash Scripting是我首推的。Oreilly Unix CD bookshelf中sed/awk第二版也是很好的书。如果你没有,到图书馆版有帖子,贴上你的email我可以发给你。还有几本象Learning the bash shell, unix/linux shell编程指南,master regular expression, Effective AWK programming等也非常值得看。


感谢yongjian了,说句实话,小弟实在不知道贴哪,干脆写在这里了
johnny_jiang_email@yahoo.com.cn
又要麻烦yongjian兄了.:thank

关于home_king的那篇精华,我查看了Learning the bash Shell - 2nd Edition (o'reilly),其中的命令行解释和home_king兄的一模一样,所以我想是不是home_king的顺序没有错误,应该有其他的解释呢?:ask
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-2-22 21:43:18 | 显示全部楼层
顶,等待yongjian兄的支持.
回复 支持 反对

使用道具 举报

发表于 2006-2-22 22:17:49 | 显示全部楼层
发了。请查。再看看吧。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-2-23 08:33:50 | 显示全部楼层
Post by yongjian
发了。请查。再看看吧。


已经收到,:thank
回复 支持 反对

使用道具 举报

发表于 2006-2-23 13:06:30 | 显示全部楼层
根据POSIX标准规定,alias的处理是在keyword和其他builtin之前,事实上也是这样,所以不管如何解释,还是以事实为准。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-2-23 14:59:43 | 显示全部楼层
Post by yongjian
根据POSIX标准规定,alias的处理是在keyword和其他builtin之前,事实上也是这样,所以不管如何解释,还是以事实为准。


I do agree with your point.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表