Chinaunix首页 | 论坛 | 博客
  • 博客访问: 64715
  • 博文数量: 17
  • 博客积分: 673
  • 博客等级: 中士
  • 技术积分: 150
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-17 16:48
文章分类

全部博文(17)

文章存档

2012年(5)

2011年(12)

分类: LINUX

2012-08-23 11:15:38

 
Bourne ShellC Shell 
differences
MsDos  
batch
Comment
sh cshfile.batcommand
19781978year introduced
#!/bin/sh#!/bin/cshUnix first line
#REM comment but parses line 
:: comment
Comment
set -vset verboseverbose on
set +vunset verboseverbose off
set -xset echo@echo ondebug mode on
set +xunset echo@echo offdebug mode off
$1, $2, ..., $9%1, %2, ..., %9command-line arguments
shiftshiftshiftshift args one position by one
$#number of command-line args
$0name of command
echo "$*" 
echo  "$1 $2 $3 ... "
glob all args in one string
echo "$@" 
echo "$1" "$2" "$3" ...
give all args as seperate strings
$?$statusexit status 
if referenced more than once 
then must save in variable
V=1set V 1set  V=1variable assignment 
no blanks around equal sign
V=$Wset V $Wset V=%W%
$V%V%Variable Ref
echo $V

echo ${V}

 echo %V%display
V='abc$Wdef'set V='abc$Wdef'literal string 
='single quotes' 
=no $variable substitution 
=no ${varible} substitution 
=useful for blanks/spaces
V="abc$Wdef" #error

V="abc${W}def" #correct

non-literal string 
="double quotes" 
=$variables substitution 
=useful for blanks/spaces
V=`expr $N + 1`executable string 
=`grave accent quotes' 
=useful for arithmetic 
=stdout assigned to variable
unset Vunsetenv Vclear variable
${V}%V%Variable Ref
cmd1 ; cmd2 sequental commands
cmd1 && cmd2 logical AND
cmd1 || cmd2 logical OR
cmd1 | cmd2

cmd1>f1; f1 < cmd2

 pipe
( subshell-cmd ) creates a subshell to run 
commands as 
a separate process
(cd /tmp;ls);ls example
{ cmds } within same shell 
brace must be followed by blank
{ date; who }>file.txt  example
echo 'msg=$V' literal string = 
single quotes = 
no $variable substitution
program 
if [ $? -eq 0 ]; then echo "program ok"; fi
if ERRORLEVEL 0 echo "program ok"testing exit status of  
last program excuted
program 
if [ $? -ne 0 ]; then echo "error"; fi;
if NOT ERRORLEVEL 0 echo "error"testing exit status of  
last program executed
if [ -n $V ]; then echo "not empty"; fi 
if test -n $V; then echo "not empty"; fi 
test -n $V; if [ $? -eq 0 ]; then echo "not empty"; fi
if  NOT %V%=="" echo "not empty"string comparison: non-zero
if [ -z $V ]; then echo "empty"; fi 
if test -z $V; then echo "empty"; fi 
test -z $V; if [ $? -eq 0 ]; then echo "empty"; fi
if %V%=="" echo "empty"string comparison: zero
if [ -f $V ]; then echo "file exists"; fi 
if test -f $V; then echo "file exists"; fi
if exist %V% echo "file exists"file comparison
if [ -d $V ]; then echo "directory exists"; fi 
if test -d $V; then echo "directory exists"; fi
file comparison
if [ -d $V ] || [ -f $W ]; then echo "dir or file"; fi
if [ $S = $T ]; then echo "string equal"; fi 
if test $S = $T ; then echo "string equal"; fi
if %S% == %T% echo "string equal"string comparison
if [ $S != $T ]; then echo "not equal"; fi 
if test $S != $T ; then echo "not equal"; fi 
if [ ! $S = $T ]; then echo "not equal"; fi 
if test ! $S = $T ; then echo "not equal"; fi
if NOT %S% == %T% echo "not equal"string comparison
if [ $I -eq $N ]; then echo "integers equal"; fiinteger comparison
if [ $I -ne $N ]; then echo "integers not equal"; fiinteger comparison
if [ $I -lt $N ]; then echo "integer less than"; fiinteger comparison
if [ $I -le $N ]; then echo "integer less than or equal"; fiinteger comparison
if [ $I -gt $N ]; then echo "integer greater than"; fiinteger comparison
if [ $I -ge $N ]; then echo "integer greater than or equal"; fiinteger comparison
if  commands; then commands; else commands; fi
for V in 1 2 3 4; do echo $V; donefor %%V in ( 1 2 3 4 ) do echo %V
N="1 2 3 4"; for V in $N; do echo $V; doneset V="1 2 3 4" 
for %%V in ( %N ) do echo %V
N=1; while [ $N -le 4 ]; do echo $N; N=`expr $N + 1`; done
f(){ echo $1; } #define a function f

f abc   #call function f with arg abc

function
date > out; ls >> out; date >> out

 ( date ; ls ; date ) > out

common output


转载自:
阅读(1424) | 评论(0) | 转发(0) |
0

上一篇:grep exp

下一篇:没有了

给主人留下些什么吧!~~