hw6 with bash

   1.  Determine a string is empty or not

if [ $var == "" ]

then
echo variable is null

fi

if [ $var != "" ]
then
echo variable is not null
fi
 

   2.  Tutorial

1) http://www.faqs.org/docs/Linux-HOWTO/Bash-Prog-Intro-HOWTO.html#ss11.1 

2) http://steve-parker.org/sh/quickref.shtml

3) http://www.faqs.org/docs/abs/HTML/

4) http://www.linuxconfig.org/Bash_scripting_Tutorial

5) http://www.linuxtopia.org/online_books/bash_guide_for_beginners/sect_04_01.html

 

   3.  Combined Logical in if/else

  if [ "$m2" == "$line" ]  && [ "$m3" == "$line" ]; then
     echo $line >> $Q4
  else
     continue
  fi 

Note: before and after the string comparison operator , there must be some space!

 

   4. Cut and save "grep" into a variable

exp: Parse out column 2 from a semicolon (;) delimited file:

$ cat myfile.txt | cut -d \; -f 2 > output.txt

m2=$(cat "$root/report/Q2.slog" | grep -e "$line"  | cut  -f 1) 

   5. Read each line of a file

 

  exec<$fname
  while read line 
  do 
    echo $line 
  done  
   6. Functio
funky () 
{ 
# This is about as simple as functions get. 
echo "This is a funky function." 
echo "Now exiting funky function." 
} 
# Function declaration must precede call.
# Now, call the functions.
funky
 
 

 

 

 

 

posted @ 2010-10-20 17:02  wangyile  阅读(290)  评论(0编辑  收藏  举报