---
title: "LEARN SHELL"
author: "edwards0307"
date: "2011-12-28T15:14:35Z"
tags: []
categories: ["数据库"]
slug: "learn-shell"
draft: false
lastmod: "2012-01-01T09:54:24Z"
id: 1328627
url: "https://killdbs.iteye.com/blog/1328627"
---

1.ORACLE\_SID=lsh

 

2.export ORACLE\_SID

 

3.#!/bin/bash

 

4.Shell variables are un-typed and may contain integer or text,Number with a decimal point will be treated as text(3.14)

 

5.variable scope: local script or all session. when export variable, variable are used in subsequently.

 

6.$ORACLE\_SID     use variable

   ${ORACLE\_SID}\_SID

 

7.echo  $ORACLE\_SID

 

8.# this  is comment

 

9.  scriptname.sh

 

10.chmod ugo+x  scriptname.sh

 

11\. ./name.sh

 

12.\[ $ORACLE\_SID="lsh" ]  conditional testing ,

 

13.if

      then

     fi

   

     if

       then

     elif

       then

     else

     fi

 

14\. matmathics comparators

      -lt    &lt;

      -le   &lt;=

      -gt   &gt;

      -ge  &gt;=

      -eq  =

      -ne  !=

 

15.string  comparators

     =

     !=

     string

 

16.file comparators

     -nt

     -ot

     -e

     -d

     -h

     -s

     -r

     -w

     -x

     -f

 

17.complex comparator

 

    -a

    -o

     !

 

18.if \[ $ORACLE\_SID="lsh" ]

 

19.if \[ $ORACLE\_SID -lt 30 ]

 

20.if \[ -e /u01/oracle/bin.sqlplus ]

 

21.if \[ -e /u01/oracle/dbs/spfile${ORACLE\_SID}.ora -a -e $ORACLE\_SID/dbs/init$ORACLE\_SID.ora ]

 

22.if \[ $ORACLE\_SID ]   check variable

 

22.ps -ef | grep "$ORACLE\_SID"

 

23\. case    in        matching string

      a)

      echo "" ;;

      b)

      echo "" ;;

      c)

      echo "";;

      \*)

      echo "";;

      esac

 

24\. while \[ $ORACLE\_SID="lsh" ]; do

 

          echo ""

          i=\`expr $i + 1\`

     done

 

25.for var in 1 a  3;do

         echo ""

    done

     

26.break; continue;

 

27.\[ -r /u01/oracle ] && echo "this is"

     \[ -r /u01/orace  ] || { echo "can not read"; exit 1; }  

  

28.{ echo "can not write" ; exit 1 ; }   anymous function

 

29.$1,$2,$3

     var=$1       specify the value of var is from running parameter    

     $* //specify all the parameters

     for var in $\*;do               ./test 1 2 3

     echo "===$var==="

     done

     $#//specify the numbersof all the parameters

30.    

    #!/bin/sh

   echo “What is your favourite OS?”  
   select var in “[Linux](http://www.ha97.com/category/linux "Linux")” “Gnu Hurd” “Free BSD” “Other”; do  
   break;  
   done  
   echo “You have selected $var”

 

   What is your favourite OS?  
  1) Linux  
  2) Gnu Hurd  
  3) Free BSD  
  4) Other  
  #? 1  
  You have selected Linux

 

 31."$SHELL"

      '\*.jpg'   

      "/$SHELL"

 

34\.

#!/bin/bash         
help()                   //must first declare, then use fun.  
{  
cat &lt;&lt; HELP  
"this is lp"  
HELP  
exit 0  
}  
\[ -n "$SHELL" ]&&help   

 

35\.

  "$SHELL"

  '$SHELL'

  "\*.jpg"

 

      

Prevent the wildcard(\*) and variable expansion

32.cat &lt;&lt;help

     sdsdsd

     sds

     help

    **Here Document:When you want to pass a few lines of text to a command,we use &lt;&lt;help ------------help**

33.exit 0   exit function

34.sh -x test.sh

     sh -n test.sh

35.shift remove the first parameter from parameter list

     shift 1

     shift 2

36.ctrl+a               !!

     ctrl+e               !$

     ctrl+l

     ctrl+u

     ctrl+k

     ctrl+y

     ctrl+r

     ctrl+c

     ctrl+d

     ctrl+z

     ./runinstall&

    

37\. ls;pwd;date     Multiple commands separated by semicolons in the  line.

      (ls;date;pwd)&gt;cat.bbk

 

38.type pwd 

39.alias  vi=vim

     alias  ll='ls-l'

     unalias    vi

40.cd /var/log

     cat /dev/null &gt;message

     cat /dev/null &gt;wtmp

41.echo "this is \`pwd\` directory"    \`pwd\`  Command substitution

42.echo ${name}  display variable

     unset  name      clear  variable

     set     display all variable

    

 43.name=bbk

      readonly bbk

 44.PATH=${PATH}:/bin/bash

      ${#PATH}  the length of the PATH

 45.arry=(abc bb cc dd)

      echo ${#arry}

      echo ${#arry\[\*]}

      echo ${#arry\[1]}

      echo ${#arry\[2]}

      echo ${arry\[0]}

46.#!bin/bash

        dno=$1

        sqlplus hr/hr &lt;&lt;EOF &gt;select.sql

        select * from emp where deptno=$dno;

        EOF

    

47.name=lsh

     echo 'this is $name'   

     this is $name

47.&gt;        redirect standoutput

     &gt;&gt;  

     2&gt;      redirect errorout

     2&gt;&gt;

48.ps -ef | grep oracle

49.echo "This is \\[\\\\\\"]()

     This is "\\"

48\.