免费注册 查看新帖 |

Chinaunix

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

看脚本学shell编程 [复制链接]

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

#!/bin/sh      
# $Xorg: startx.cpp,v 1.3 2000/08/17 19:54:29 cpqbld Exp $
#
# This is just a sample implementation of a slightly less primitive
# interface than xinit. It looks for user .xinitrc and .xserverrc
# files, then system xinitrc and xserverrc files, else lets xinit choose
# its default. The system xinitrc should probably do things like check
# for .Xresources files and merge them in, startup up a window manager,
# and pop a clock and serveral xterms.
#
# Site administrators are STRONGLY urged to write nicer versions.
#
# $XFree86: xc/programs/xinit/startx.cpp,v 3.16tsi Exp $
上面这一部分主要是注释,第一行“#!/bin/sh"表示这个脚本的解释程序是/bin/sh
userclientrc=$HOME/.xinitrc
sysclientrc=/usr/X11R6/lib/X11/xinit/xinitrc
userserverrc=$HOME/.xserverrc
sysserverrc=/usr/X11R6/lib/X11/xinit/xserverrc
defaultclient=/usr/X11R6/bin/xterm
defaultserver=/usr/X11R6/bin/X
defaultclientargs=""
defaultserverargs=""
clientargs=""
serverargs=""
以上是一些变量的定义,在脚本中将要用到!

if [ -f $userclientrc ]; then
    defaultclientargs=$userclientrc     //如果~/.xinitrc存在,使用
elif [ -f $sysclientrc ]; then
    defaultclientargs=$sysclientrc      //否则使用系统提供的xinitrc
fi
以上完成了一个条件执行。设定了X启动的客户端参数。
if 条件;then 语句1  elif 条件;then 语句2 fi
if [ -f $userserverrc ]; then
    defaultserverargs=$userserverrc
elif [ -f $sysserverrc ]; then
    defaultserverargs=$sysserverrc
fi
以上完成了X启动的服务器端参数。
whoseargs="client"
listen_tcp="-nolisten tcp"
while [ x"$1" != x ]; do          //$1表示脚本运行的第一个参数
    case "$1" in                  
    -listen_tcp)
    listen_tcp=""
    ;;
    # '' required to prevent cpp from treating "/*" as a C comment.
    /''*|\./''*)
    if [ "$whoseargs" = "client" ]; then
     if [ x"$clientargs" = x ]; then
        client="$1"
     else
        clientargs="$clientargs $1"
     fi
    else
     if [ x"$serverargs" = x ]; then
        server="$1"
     else
        serverargs="$serverargs $1"
     fi
    fi
    ;;
    --)
    whoseargs="server"
    ;;
    *)
    if [ "$whoseargs" = "client" ]; then
     clientargs="$clientargs $1"
    else
     # display must be the FIRST server argument
     if [ x"$serverargs" = x ] && \
         expr "$1" : ':[0-9][0-9]*$' > /dev/null 2>&1; then
        display="$1"
     else
        serverargs="$serverargs $1"
     fi
    fi
    ;;
    esac
    shift
done
startx默认启动下是不带参数的,因此上面代码并不执行!
# process client arguments
if [ x"$client" = x ]; then
    # if no client arguments either, use rc file instead
    if [ x"$clientargs" = x ]; then
    client="$defaultclientargs"
    else
    client=$defaultclient
    fi
fi
# process server arguments
if [ x"$server" = x ]; then
    # if no server arguments or display either, use rc file instead
    if [ x"$serverargs" = x -a x"$display" = x ]; then
    server="$defaultserverargs"
    else
    server=$defaultserver
    fi
fi
if [ x"$XAUTHORITY" = x ]; then
    XAUTHORITY=$HOME/.Xauthority
    export XAUTHORITY
fi
removelist=
# set up default Xauth info for this machine
case `uname` in
Linux*)
    if [ -z "`hostname --version 2>&1 | grep GNU`" ]; then
        hostname=`hostname -f`
    else
        hostname=`hostname`
    fi
    ;;
*)
    hostname=`hostname`
    ;;
esac
authdisplay=${display:-:0}
mcookie=`dd if=/dev/urandom bs=16 count=1 2>/dev/null | hexdump -e \\"%08x\\"`
dummy=0
# create a file with auth information for the server. ':0' is a dummy.
xserverauthfile=$HOME/.serverauth.$$
xauth -q -f $xserverauthfile  EOF
add :$dummy . $mcookie
EOF
serverargs=${serverargs}" -auth "${xserverauthfile}
# now add the same credentials to the client authority file
# if '$displayname' already exists don't overwrite it as another
# server man need it. Add them to the '$xserverauthfile
以上代码是startx脚本代码,在探寻startx启动和kdm启动桌面环境的不同时,读到过这段shell脚本。也算是对自己收获的一点儿小节吧!


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

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP