test%20command%20-%201 - PowerPoint PPT Presentation

About This Presentation
Title:

test%20command%20-%201

Description:

test command - 1 Shell Script ,test . test ... – PowerPoint PPT presentation

Number of Views:97
Avg rating:3.0/5.0
Slides: 9
Provided by: CYU4
Category:

less

Transcript and Presenter's Notes

Title: test%20command%20-%201


1
test command - 1
  • Shell Script??????????????????,test?????????.
    ????? test??????????? ???.
  • ltlt ???test?????????? gtgt
  • test d file ??file?????
  • test -f file ??file???????
  • test -L file ??file??????
  • test r file ??file????
  • test -w file ??file????
  • test -x file ??file?????
  • test e file ??file????
  • test -s file ??file??????gt0
  • test -S file ??file?????Socket

2
test command-2
  • ???test???????if?????????.
  • ltlt ???test?????????? gtgt
  • test n1 eq n2 ??? n1n2 ?
  • test n1 ne n2 ??? n1?n2 ?
  • test n1 ge n2 ??? n1gtn2 ?
  • test n1 gt n2 ??? n1gtn2 ?
  • test n1 le n2 ??? n1ltn2 ?
  • test n1 lt n2 ??? n1ltn2 ?

3
test command-3
  • ???test???? expr????????(true)??(false)???
  • test !expr ??expr???????
  • test expr1 a expr2 ???????AND???
  • test expr1 o expr2 ???????OR???

???test??????(s)??? test str1 str2
??????????? test str1 str2 ??????????? test
str1 ! str2 ??????????? test n str
??????????0? test z str ??????????0?
4
Shell Script ??
?? makex
  • ??Unix??,???????????,??????????script????
  • ??????
  • sh makex makex
  • makex ??

make executable file !/bin/sh chmod ux
1 echo 1 is now executable ls l 1
?? morewc
  • ????????wc??????????????,???????script???????????
  • ??????
  • makex morewc
  • morewc ??

make wc more readable !/bin/sh set wc
1 echo File 4 echo lines 1 echo words
2 echo characters 3
5
Shell Script ??
?? remember
????script?????????????????. ?????? makex
remember remember
A daily reminder service !/bin/sh echo
remind of the week Set date case 1 in
??) echo Plan the week ??) echo meet
teacher ??) echo Join the club ??)
echo Write homework ??) echo Wash my
cloth ??) echo go home ??) echo
enjoy the NBA ) echo ?..???????? esac
??????????????? .bash_profile ? ?????? source
.login ?? ./.profile
6
Shell Script ??
??ezdel
delete file interactively !/bin/sh fname
1 if test ! f fname then echo There
is no file \fname\. else echo Do you
want to delete \fname\? read choice
if test choice y then rm fname
echo \fname\ deleted. else
echo \fname\ not deleted. fi fi
?????????????????????,??????script??????????. ???
??? makex ezdel ezdel ??
7
Shell Script ??
??myspell
??spell??????,????,??????????, ???????????. ?????
? makex myspell myspell ??
improve my spell checker !/bin/sh echo enter a
word for spell check read fword for word in
spell fword do linegrep n word word
echo echo Misspelled word
word echo line done
8
Shell Script ??
test integer a and b who is bigger !/bin/sh A
1 B 2 if test A gt B then echo
A gt B else if test A lt B then
echo A lt B else echo A
B fi fi
??testab
?????????????? ?????? makex testab testab 6
8 (??2?????? ??)
add number from 1 to 9 !/bin/sh sum0 for i
in 1 2 3 4 5 6 7 8 9 do sumexpr sum
i done echo The sum of 1-9 is sum
??sum-t
???1-9???. ?????? makex sum-t sum-t
Write a Comment
User Comments (0)
About PowerShow.com