Shell Script Learn

Source: Internet
Author: User

The previous writing test program used scripts to raise interest, combined with specific cases, to test the results of learning. Finally understand a slightly more complex shell script. There are still a lot of technical things in there.

Declared variable name, Bluetooth_sleep_path is not used for [HTML] view plain copy bluetooth_sleep_path=/proc/bluetooth/sleep/proto log_tag= " Qcom-bluetooth "Log_name=" ${0}: "


declaring functions

$#----The total number of arguments passed to the program
$?----the previous code or shell program exits in the shell, returns 0 if normal exits, and a non-0 value instead. The
$*----A string that consists of all the arguments passed to the program.
    $-----provide options when the shell starts or uses the SET command
    $?----The value returned after the previous command was executed
     $$----The current shell's process number
    $!----The process number of the previous child process
    $@----All parameters, each enclosed in double brackets
    $n----Positional parameter value, n for position
    $----Current shell name [html]  view Plain copy loge  () & nbsp;  {     /system/bin/log -t  $LOG _tag -p e  "$LOG _name  $@ "  }      logi  ()    {     /system/bin/log  -t  $LOG _tag -p i  "$LOG _name $@"   }      failed  ()    {     loge  "$1: exit code $2"      exit  $2  }  

& Symbols I understand the meaning of running in the background so that $! represents the process number of the previous subprocess, and the usage can refer to test2.sh [html]  view plain copy start_hciattach  ()     {     /system/bin/hciattach -n  $BTS _device  $BTS _type  $BTS _baud  &     hciattach_pid=$!     logi  "start_hciattach:  pid =  $hciattach _pid "     echo 1 >  $BLUETOOTH _sleep_path   }      kill_hciattach  ()    {     echo 0  >  $BLUETOOTH _sleep_path     logi  "kill_hciattach: pid = $ Hciattach_pid "     ## careful not to kill zero or null!      kill -TERM  $hciattach _pid     # this shell  DOESN ' t exit now -- wait returns for normal exit  }   

The


gets the parameters and resolves them, similar to the C language. BLNP is without parameters, t:s: With a colon for parameters,
Default output usage [html]  view plain copy while getopts  "blnpt:s:"  f    do     case  $f  in     b | l |  n | p)   opt_flags= "$opt _flags -$f"  ;;      t)       timeout= $OPTARG;;      s)       initial_speed= $OPTARG;;      \?)      echo  $USAGE; exit 1;;      esac   done   shift $ (($OPTIND-1))   

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.