我正在挖掘 mysql_safe (试图添加一些选项),我遇到了他们用来从启动代理分配变量的这种 bash 脚本技术:com.mysql.mysqld.plist(我在 mac 上)。
现在 mysqld_safe 不知道 LaunchCtl 正在调用它,所以我假设 LaunchCtl 将任何选项转换为命令行参数,但我发现这个 sytnax 很有趣。有人知道这是如何工作的吗?
我了解 Bash 中 Case/Switch 的基础知识:
case "$myval" in
switch1) do something;;
switch2) do something;;
*) do whatever fallthrough logic;;
esac
默认情况下使用 * 在下面的脚本块中,arg 值为:“--basedir=”或“--datadir=”或“--pid-file=”等但是 * 中的 * 是怎么回事那里?
那是switch语句中的正则表达式吗?
有反向引用?
for arg do
# the parameter after "=", or the whole $arg if no match
val=`echo "$arg" | sed -e 's;^--[^=]*=;;'`
# what's before "=", or the whole $arg if no match
optname=`echo "$arg" | sed -e 's/^\(--[^=]*\)=.*$/\1/'`
# replace "_" by "-" ; mysqld_safe must accept "_" like mysqld does.
optname_subst=`echo "$optname" | sed 's/_/-/g'`
arg=`echo $arg | sed "s/^$optname/$optname_subst/"`
arg=`echo $arg | sed "s/^$optname/$optname_subst/"`
case "$arg" in
# these get passed explicitly to mysqld
--basedir=*) MY_BASEDIR_VERSION="$val" ;;
--datadir=*) DATADIR="$val" ;;
--pid-file=*) pid_file="$val" ;;
--plugin-dir=*) PLUGIN_DIR="$val" ;;
--user=*) user="$val"; SET_USER=1 ;;
...
...
*)
if test -n "$pick_args"
then
append_arg_to_args "$arg"
fi
;;
esac