LINUX SHELL综合案例:指定字串的截取,字串长度,rpath修改

  这个脚本的思路是这样的

  • 新的rpath长度不通超过文件已有的rpath
  • 不同库的关键字,可能是RUNPATH,也可能是RPATH
  • 从文件中读取rpath
  • 截取rpath
  • 计算长度
  • 根据长度,使用不同长度的rpath

具体结果

function change_rpath()
{
    RPATH01=.
    RPATH07=\$ORIGIN
    RPATH12=\$ORIGIN:/lib
    RPATH30=\$ORIGIN:/lib/aarch64-linux-gnu
    RPATH35=\$ORIGIN:/lib:/lib/aarch64-linux-gnu

    RPATH_INFO=`chrpath ${1}`
#libHpws.Generic.so: RPATH=:/libs
echo ${RPATH_INFO}
    RPATH=`echo ${RPATH_INFO#*RPATH=}`
    if [[ ${RPATH_INFO} == ${RPATH} ]]; then
        RPATH=`echo ${RPATH_INFO#*RUNPATH=}`
    fi

#:/libs
echo ${RPATH}

    length=${#RPATH}
#6
echo ${length}

    if [[ ${length} -ge 35 ]]; then
        RPATH=${RPATH35}
    elif [[ ${length} -ge 30 ]]; then
        RPATH=${RPATH30}
    elif [[ ${length} -ge 12 ]]; then
        RPATH=${RPATH12}
    elif [[ ${length} -ge  7 ]]; then
        RPATH=${RPATH07}
    else
        RPATH=${RPATH01}
    fi
    result=`chrpath -r ${RPATH} ${1}`

    # chrpath ${1}
}

你可能感兴趣的:(linux,linux,运维,服务器)