PCB论坛网

 找回密码
 注册
查看: 2603|回复: 11

新的問題

[复制链接]
发表于 2004-11-28 15:58:45 | 显示全部楼层 |阅读模式

好久沒來逛了,我這回有新的問題想請教版主,對你們來說小kiss了,不過我想麻煩你能教教我.

DO_INFO -t JOB -e $JOB -d ATTR

DO_INFO -t matrix -e $JOB/matrix -d ROW

@ laynumber = 0

@ laycount++

這些語法我看不大明白,請幫我解釋一下? 好嗎.

回复

使用道具 举报

发表于 2004-11-28 16:34:23 | 显示全部楼层
以下是引用小琴儿在2004-11-28 15:58:45的发言:

好久没来逛了,我这回有新的问题想请教版主,对你们来说小kiss了,不过我想麻烦你能教教我.

DO_INFO -t JOB -e $JOB -d ATTR

DO_INFO -t matrix -e $JOB/matrix -d ROW

@ laynumber = 0

@ laycount++

这些语法我看不大明白,请帮我解释一下? 好吗.

DO_INFO -t JOB -e $JOB -d ATTR 得到这个job的属性

DO_INFO -t matrix -e $JOB/matrix -d ROW 得到marix中所有列的资讯

@ laynumber = 0 设定初始值为o

@ laycount++ ---> set laycount = `echo "$layconut + 1"|bc` [em05]

建议您先学学c shell的基本指令...........

回复 支持 反对

使用道具 举报

 楼主| 发表于 2004-11-28 16:41:07 | 显示全部楼层

謝謝版主,c-shell正在學習中,有問題還望多指教.

回复 支持 反对

使用道具 举报

 楼主| 发表于 2004-11-28 16:46:25 | 显示全部楼层
還想請問版主,c-shell學習,我有買相關的書,但是好像有很多沒有談及到,不知道版主能給我一個建議了???
回复 支持 反对

使用道具 举报

发表于 2004-11-28 22:59:48 | 显示全部楼层
以下是引用小琴儿在2004-11-28 16:46:25的发言: 还想请问版主,c-shell学习,我有买相关的书,但是好像有很多没有谈及到,不知道版主能给我一个建议了???

先学以下指令语法.........快速入门法:

1. if

2. foreach

会这两个就能做很多事了,若想多了解一点,看需求再学吧.......... [em05]

回复 支持 反对

使用道具 举报

发表于 2004-11-29 20:49:30 | 显示全部楼层
有什么样的好书介绍两本吧~!
回复 支持 反对

使用道具 举报

发表于 2004-11-29 22:27:44 | 显示全部楼层
以下是引用黑夜里的鱼在2004-11-29 20:49:30的发言: 有什么样的好书介绍两本吧~!

看完以下的简介,若完全懂了就开始写genesis2000 50%以上的程式了...........

1. switch 的用法,注意每一个 case 必须要以 breaksw 结尾
  否则会继续执行下一个 case 的命令
   (1) 另外, $< 的意思是取得使用者的 stand input
   (2) echo 若加上 -n 的选项,则游标会停留在该行最后 

echo -n "Input one color:  "
set STOPLIGHT = $<
switch ($STOPLIGHT)
  case red:
       echo "red"
       breaksw
  case orange:
       echo "orange"
       breaksw
  case green:
       echo "green"
       breaksw
  default:
       echo "you input $STOPLIGHT"
endsw

--------------------------------------------------------------------
2. 利用 set 来取得变数, set ABC = "I am ABC"
   也可以利用 `command` 来取得命令
   且外,case 也可以用万用字元 * 来代替

set VER = `uname -r`
switch ($VER)
  case 5.5:
       echo "run the setup of $VER"
       breaksw
  case 5.3:
       echo "run the setup of $VER"
       breaksw
  case 5.*:
       echo "like 5.x"
       breaksw
  case 4.*:
       echo "like 4.x"
       breaksw
  default:
       echo "no idea"
endsw

--------------------------------------------------------------------
3. if 的语法,比较数字

set n1 = 1
set n2 = 2
if ($n1 == $n2) then
  echo "$n1 Equal $n2"
else
  echo "$n1 Not Equal $n2"
endif


--------------------------------------------------------------------
4. if 的语法,比较字串

set n1 = abcdef
set n2 = abcde
if ($n1 == $n2) then
  echo "$n1 Equal $n2"
else
  echo "$n1 Not Equal $n2"
endif


--------------------------------------------------------------------
5. if 的语法,比较相似的字串

set n1 = abcdef
set n2 = abcde
if ($n1 =~ $n2) then
  echo "$n1 Like $n2"
else
  echo "$n1 Not Like $n2"
endif


--------------------------------------------------------------------
6. if 的语法,比较数字的大小

set n1 = 1
set n2 = 2
if ($n1 > $n2) then
  echo "$n1 > $n2"
else
  echo "$n1 < $n2"
endif


--------------------------------------------------------------------
7. 每分钟执行一次的程式

#  mm 等于当天时间的【分钟】数
set mm = `date | cut -d' ' -f4 | cut -d: -f2`

if ( -r $0.out ) then
  rm $0.out
  touch $0.out
else
  touch $0.out
endif

while ( $mm <= 16 )
  set mm = `date | cut -d' ' -f4 | cut -d: -f2`
  echo "$mm now is `date`"
  sleep 60
  #echo "$mm now is `date`" >> $0.out
end
echo "Over" >> $0.out  
  

--------------------------------------------------------------------
8. 一个回圈的范例,并且利用 expr 去作加的动作
   回圈的语法如下:
      foreach number (1 2 3)
        echo $number
      end

set counter = 0
while ($counter <= 10)
  echo "sleeping for 5 seconds"
  sleep 5
  counter = `expr $counter + 1 `
end


--------------------------------------------------------------------
9. 设定一个用当天月份与日期作为档案名称的程式
   如今天是 10/02 , 则 $prefix 会等于 该程式 + 1002
   date.csh1002

set prefix = `basename $0``date '+ %m%d'`
echo $0
echo $prefix


--------------------------------------------------------------------
10. 移除在 foreach 回圈内指定的档案内的 font 字串


foreach file ([b,e,g,h,s]*.html)
  echo -n "Processing $file, remove the line number `grep -n font $file`"

  # $log 表示这个 $file 有几个 font 字串
  set log = `grep -c font $file` 
  if ( $log == '0' ) then
    echo ", pass $file"
  else
    # 先找出该档案的第一次出现 font 的行数,如果 3,则 $cmd = 3d
    set cmd = `grep -n font $file | cut -d: -f1 | head -1`d
    # 利用 sed 去执行删除的动作,并把结果输出到 ${file}1
    sed $cmd $file > ${file}1
    # 如果 ${file}1 没有资料,则 passing
    if ( -z ${file}1 ) then
      echo " , ${file}1 is zero"
    else
      cp ${file}1 $file
      rm {$file}1
      echo " ,  $file remove ok"
    endif
  endif
end

# 后来看过 sed 的更进一步用法,发现先前写的太笨了,试试这个
# sed /font/d $file > ${file}1
# 一次 OK, 我真是大笨蛋

--------------------------------------------------------------------
11. 功能:将指定的档案中,出现第一次【回】的那一行,加上 <title> xxxx </title>

foreach file (sky*.html)
  set filetitle = ftitle
  # 主要部份为 sed 部份    s/^  *//   表示将该行第一个字元前的空白删除
  echo "<title>`grep 回 $file | head -1 | sed -e 's/^  *//'`</title>" > $ftitle

  # 将刚刚那一行,再插回去
  head -1 $file > ${file}head
  sed 1d $file > ${file}1
  cat $ftitle >> ${file}head
  cat ${file}1 >> ${file}head
  cp ${file}head $file
  rm ${file}1
  rm $ftitle
  rm ${file}head

  echo "$file ok"
end

--------------------------------------------------------------------
12. 一个实际建立一个 ftp server 的程式
  里面包括许多应用,相当有参考价值 
    ( 未完成 )

set path = ( /usr/bin /usr/sbin )
#
set true = `grep -c ftp /etc/passwd`
if ( $true == 0 ) then
  echo "no ftp user in your system"
  echo -n "do you want to create the ftp user? "
  set answer = $<
  if ($answer == 'y' || $answer == 'Y') then
    set maxid = `sort /etc/passwd | tail -1 | cut -d: -f3`
    echo $maxid
    set newid = `expr $maxid + 1`
    echo $newid
    echo "/usr/sbin/useradd -d /home1/ftp -u $newid -s /etc/false ftp"
  endif
else
  echo "Good. Your system already has the ftp user. "
  set ftphome = `grep ftp: /etc/passwd | cut -d: -f6`
  echo $ftphome
endif

if ( -z $ftphome ) then
  echo "ftphome must be non-null"
  exit 2
endif  

if ( $ftphome == "/usr" || $ftphome == "/" ) then
  echo "ftphome can't be / or /usr"
  exit 2
endif

# create the ftp home directory
if ( ! -d $ftphome ) then
  echo "mkdir $ftphome"
endif

echo "Setting up the ftphome for SunOS `uname -r`"

if ( ! -d $ftphome ) then
  echo "mkdir -p $ftphome/usr/bin"
endif

cp /bin/ls $ftphome/usr/bin

chmod 111 $ftphome/usr/bin/ls
chown root $ftphome/usr/bin
chmod 555 $ftphome/usr/bin

if ( -r $ftphome/bin ) then
  mv -f $ftphome/bin $ftphome/Obin
endif
ln -s usr/bin $ftphome


--------------------------------------------------------------------
13. 取得该使用者的 UID

if ( $#argv == 0 )  then
  echo "$0 usage: $1 username"
  exit 2
endif

set uid = `grep $1 /etc/passwd | cut -d: -f3`
echo $uid


--------------------------------------------------------------------
14. 将指定档案内的 html 取代成 htm

foreach file ( *.html )
  echo "Processing $file ..."
  sed s/html/htm/ $file > ${file}1
  cp ${file}1 $file
  rm ${file}1
end


--------------------------------------------------------------------
15. 一个简简单单的范例,看看就好

#!/bin/csh -f
echo .................
echo WELCOME to \* TAPE COPY \*
echo .................
echo Enter your name:
# $< can read from stand input
set name = $<
echo "   "
echo Hi $name \!
set D = `date`
echo Today\'s date is $D[1] $D[2] $D[3]
if ($D[1] == Mon) then
  echo -------------------------------------------------------------
  echo Today is $D[1]day $name, it\'s time to copy your directorys\!
  echo -------------------------------------------------------------
else
  echo -------------------------------------------------------------
  echo Today is $D[1]day $name, no tape copies today\!
  echo -------------------------------------------------------------
endif
  

--------------------------------------------------------------------
16. 一个 finger 的程式

set FINGER = "/usr/ucb/finger"

if ( -x $FINGER ) then
  if ( $#argv == 0 ) then
    cat << TAG
   ---------------------------------
    Hahahah ....   
   ---------------------------------
TAG
  else
    $FINGER "$*"
  endif

else
  echo "Cannot find finger on this system."
endif


--------------------------------------------------------------------
17. 取得变数的方法

set W = `who -r`
echo $W[9] 



--------------------------------------------------------------------
18. 更改档案名称,将 *.html --> *.htm

# rename *.html to *.htm
echo -n "This will change *.html to *.htm. Can I continue ? (y/n) : "
set input = $<
if ( $input != "y" && $input != "Y" ) then
  echo "Ok. Quit..."
  exit 2
endif

foreach file ( *.html )
  echo "Processing $file to `basename $file .html`.htm "
  mv $file `basename $file .html`.htm
end

--------------------------------------------------------------------
19. 更改档案名称,将 *.htm --> *.html

echo -n "This will change *.htm to *.html. Can I continue ? (y/n) : "
set input = $<
if ( $input != "y" && $input != "Y" ) then
  echo "Ok. Quit..."
  exit 2
endif

# rename *.htm to *.html
foreach file ( *.htm )
  echo "Processing $file to `basename $file .htm`.html "
  mv $file `basename $file .htm`.html
end

--------------------------------------------------------------------
20. 将大写的档名改成小写的档名
    tr string1 string2  会将 standard input 的字串,
    所对应到的 string1, 都以 string2 取代

foreach file ( * )
  mv $file `echo $file | tr '[A-Z]' '[a-z]'`
end

--------------------------------------------------------------------
21. 将小写的档名改成大写的档名
    
foreach file (*)
  mv $file `echo $file | tr '[a-z]' '[A-Z]'`
end

--------------------------------------------------------------------
[em05]
回复 支持 反对

使用道具 举报

 楼主| 发表于 2004-11-30 19:02:18 | 显示全部楼层

版主了解得很多哦,版主能告訴我在書店哪里有這些相關內容的書賣呢?或都是什麼樣的書啊!!!!!!!!

[em09]
[此贴子已经被作者于2004-11-30 19:04:03编辑过]
回复 支持 反对

使用道具 举报

发表于 2004-11-30 22:16:49 | 显示全部楼层
以下是引用小琴儿在2004-11-30 19:02:18的发言:

版主了解得很多哦,版主能告诉我在书店哪里有这些相关内容的书卖呢?或都是什么样的书啊!!!!!!!!

[em09]

一般书店对于介绍c shell的书并不多,但在台湾台北重庆南路的天珑书局有蛮多的书可供参考!

去上海书局看看,听说那的书也不少..........

回复 支持 反对

使用道具 举报

发表于 2005-10-24 16:48:31 | 显示全部楼层
/?????????????????
回复 支持 反对

使用道具 举报

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

本版积分规则

Archiver|小黑屋|手机版|PCB设计论坛|EDA论坛|PCB论坛网 ( 沪ICP备05006956号-1 )

GMT+8, 2024-5-14 23:07 , Processed in 0.131065 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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