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))