免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1277 | 回复: 0
打印 上一主题 下一主题

olaris 系统管理员指南 第3版 §3 shell [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-09-10 10:50 |只看该作者 |倒序浏览

                               
§2    shell
Solaris 有3种基本的shell :the
Bourne shell (the default), the C shell, and the Korn shell.
还有3种免费的shell:   The Bourne-Again shell (bash), the TC shell (tcsh), and the
Z shell (zsh).


  
   
   Feature
   
   
   Bourne
   
   
   bash
   
   
   zsh
   
   
   C
   
   
   tcsh
   
   
   Korn
   
  


  
  Aliases.
  
  
  Yes
  
  
  Yes
  
  
  Yes
  
  
  Yes
  
  
  Yes
  
  
  Yes
  


  
  Command-line editing.
  
  
  No
  
  
  Yes
  
  
  Yes
  
  
  Yes
  
  
  Yes
  
  
  Yes
  


  
  Enhanced cd.
  
  
  No
  
  
  Yes
  
  
  Yes
  
  
  Yes
  
  
  Yes
  
  
  Yes
  


  
  History list.
  
  
  No
  
  
  Yes
  
  
  Yes
  
  
  Yes
  
  
  Yes
  
  
  Yes
  


  
  Ignore CTRL-D (ignoreeof).
  
  
  No
  
  
  Yes
  
  
  Yes
  
  
  Yes
  
  
  Yes
  
  
  Yes
  


  
  Initialization file separate from .profile.
  
  
  No
  
  
  Yes
  
  
  Yes
  
  
  Yes
  
  
  Yes
  
  
  Yes
  


  
  Job control.
  
  
  Yes
  
  
  Yes
  
  
  Yes
  
  
  Yes
  
  
  Yes
  
  
  Yes
  


  
  Logout file.
  
  
  No
  
  
  Yes
  
  
  Yes
  
  
  Yes
  
  
  Yes
  
  
  No
  


  
  Protect files from overwriting (noclobber).
  
  
  No
  
  
  Yes
  
  
  Yes
  
  
  Yes
  
  
  Yes
  
  
  Yes
  


  
  Syntax compatible with Bourne shell.
  
  
  Yes
  
  
  Yes
  
  
  Yes
  
  
  No
  
  
  No
  
  
  Yes
  


§3.1 shell 的通用命令
设置默认shell可以通过修改/etc/passwd,  执行admintool&, 或者AdminSuite 3.0..
也可以使用命令行临时改变shell
(csh, ksh, sh, bash, tcsh)

§3.2 The Bourne Shell
Solaris默认的shell, 由贝尔实验室的Steve Bourne开发,是一个小型shell.
初始化文件: .profile
环境变量的定义: $ PS1=oak$;export PS1
别名可以由函数创建.
脚本生效: 采用. .profile

§3.3 The C Shell
C shell有特色的地方是命令历史查询
初始化文件: .login,然后是.cshrc, 从命令行启动,只读取,所以环境变量最好放在.cshrc中.
环境变量的定义: oak% setenv DISPLAY rogue:Ø
别名: alias ftp "ftp -i",
历史命令: set history=1Ø,!!重复上一条命名.!$上一命令行的变量.!n执行第多少行命令.添加新的命令:oak% newcommandnewcommand: Command not foundoak% rehashoak% newcommandoak%编辑命令:oak% history    31  cd    32  ls    33  cd /home/frame3.1    34  ls    35  cd ..    36  tar cvf /dev/rmt/0 frame3.1    37  lp questionnaire    38  lpstat -t    39  echo $PaTH    40  historyoak% !39:s/a/A/echo $PATH.:/home/winsor:/usr/openwin/bin:/usr/deskset/bin:/home/ winsor/bin:/bin:/home/bin:/etc:/usr/etc:/usr/bin:/home/ frame3.1/binoak%
§3.4 The Korn Shell
Bourne shell 的超集.
C shell有特色的地方是命令历史查询
初始化文件: .profile and .ksh-env,多数命令建议放在.ksh-env中,在.profile中可能不能执行.
环境变量的定义: VARIABLE=value;export VARIABLE.
$ ENV=$HOME/.kshrc;export ENV  这部分必须放在.profile中.

查看变量:
set –o

  
   
   Korn Shell
   Options
   
  
  
   
   Option
   
   
   Default
   
   
   Description
   
  


  
  allexport
  
  
  off
  
  
  Automatically export variables when
  defined.
  


  
  bgnice
  
  
  on
  
  
  Execute all background jobs at a lower
  priority.
  


  
  emacs
  
  
  off
  
  
  Set emacs/gmacs as the
  in-line editor.
  


  
  errexit
  
  
  off
  
  
  If a command returns the value False, the
  shell executes the ERR trap (if set) and immediately exits.
  


  
  gmacs
  
  
  off
  
  
  Set gmacs as the in-line
  editor.
  


  
  ignoreeof
  
  
  off
  
  
  When the interactive option is also set,
  the shell does not exit at end-of-file. Type exit to quit the shell.
  
  


  
  interactive
  
  
  on
  
  
  The shell automatically turns the
  interactive option on so that shell prompts are displayed.
  


  
  keyword
  
  
  off
  
  
  The shell puts each word with the syntax
  of a variable assignment in the variable assignment list.
  


  
  markdirs
  
  
  off
  
  
  Display a / following the names
  of all directories resulting from path name expansion.
  


  
  monitor
  
  
  on
  
  
  Enable job control.
  


  
  noclobber
  
  
  off
  
  
  Do not overwrite an existing file when
  the redirect operator (>) is used.
  


  
  noexec
  
  
  off
  
  
  Read commands but do not execute them.
  You can use this option to debug shell script syntax errors.
  


  
  noglob
  
  
  off
  
  
  Disable file name expansion.
  


  
  nolog
  
  
  off
  
  
  Do not store function definitions in the
  history file.
  


  
  nounset
  
  
  off
  
  
  Display an error message when the shell
  tries to expand a variable that is not set.
  


  
  privileged
  
  
  off
  
  
  When this option is off, the real UID and
  GID are used. When this option is on, the UID and GID are set to the values
  that were in effect when you started the shell.
  


  
  restricted
  
  
  off
  
  
  Set a restricted shell.
  


  
  trackall
  
  
  off
  
  
  Make command-tracked aliases when they
  are first encountered.
  


  
  verbose
  
  
  off
  
  
  Display the input as it is read.
  


  
  vi
  
  
  off
  
  
  Set vi as the in-line
  editor.
  


  
  viraw
  
  
  off
  
  
  Specify character-at-a-time input from vi.
  


  
  xtrace
  
  
  off
  
  
  Display commands and arguments as they
  are executed.
  


比如打开vi     set -o vi作为命令行编辑器,关闭set +o vi, 这个vi默认是插入模式别名: alias a=alias, 查看别名设置 预定义的别名如下:

  
   
   Table 23. Korn
   Shell Preset Aliases
   
  
  
   
   Alias
   
   
   Value
   
   
   Definition
   
  


  
  autoload
  
  
  typeset -fu
  
  
  Define an autoloading function.
  


  
  false
  
  
  let -0
  
  
  Return a non-zero status. Often used to
  generate infinite until loops.
  


  
  functions
  
  
  typeset -f
  
  
  Display a list of functions.
  


  
  hash
  
  
  alias -t -
  
  
  Display a list of tracked aliases.
  


  
  history
  
  
  fc -l
  
  
  List commands from the history file.
  


  
  integer
  
  
  typeset -i
  
  
  Declare integer variable.
  


  
  nohup
  
  
  nohup
  
  
  Keep jobs running even if you log out.
  


  
  r
  
  
  fc -e -
  
  
  Execute the previous command again.
  


  
  stop
  
  
  kill -STOP
  
  
  Suspend job.
  


  
  suspend
  
  
  kill -STOP
  $$
  
  
  Suspend job.
  


  
  true
  
  
  :
  
  
  Return a 0 exit status.
  


  
  type
  
  
  whence -v
  
  
  Display information about commands.
  

  历史命令: 默认128条, $HOME/.sh_history$ HISTSIZE=2ØØ;export HISTSIZEFc –l 和 history 可以显示历史命令.fc有更多的功能,暂略


§3.5       The Bourne-Again Shell
吸收了Korn and C
shells的优点,符合IEEE POSIX Shell and Tools
specification (IEEE Working Group 1003.2).
--login    非交互式登陆
先读取/etc/profile file,而后~/.bash_profile, ~/.bash-login,
and ~/.profile, 可以使用—noprofile, 不读取这些文件.
退出时执行~/.bash_logout

if [ -n "$BASH_ENV" }; then . "$BASH_ENV"; fi
§3.6       The TC Shell
UNIX C shell的增强,并且完全兼容,有以下特性:a command-line editor,
programmable word completion, spelling correction, a history mechanism, job
control, and a C-like syntax.

先执行/etc/csh.cshrc and /etc/csh.login,而后
·        
~/.tshrc
·        
~/.cshrc (if /.tshrc is not found)
·        
~/.history (or the value of the histfile shell variable)
·        
~/.login
·        
~/.cshdirs (or the value of the dirsfile shell variable)
非交互式只执行: /etc/csh.cshrc and ~/.tshrc or ~/.cshrc


§3.6       The Z Shell
类似Korn shell的增强,可做为交互式login shell和a shell script command processor.
功能: command-line
editing, built-in spelling correction, programmable command completions, shell
functions (with autoloading), a history mechanism, and a host of other
features.
       其他暂略
               
               
               
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/21908/showart_378196.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP