Linux learning path using scripts to copy binaries and required library files

Source: Internet
Author: User

The special syntax of Bash is introduced first

${parameter#*word}

Where parameter is a variable, word is a delimiter, which means that the string from the leftmost left character of the variable to the first match to the delimiter (word) is removed

${parameter##*word}: Indicates that the string from the leftmost character of the variable to the last match to the delimiter is stripped off

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/42/76/wKioL1PXsiOTZxIwAAB2LxV16k8393.jpg "title=" Para.png "alt=" Wkiol1pxsiotzxiwaab2lxv16k8393.jpg "/>

Note: Do not add the $ sign to the variable


When * in front of the delimiter (word), indicates that the match is started from the left

When * is followed by a delimiter (word), the match is started from right

${parameter%word*}: Indicates that the string from the rightmost character start to the first match to the delimiter is all removed

${parameter%%word*}: Indicates that the string from the beginning of the rightmost character to the last match to the delimiter is all removed

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/42/77/wKioL1PXs7jC8iJuAABuuUCiSAE719.jpg "title=" Pa2.png "alt=" Wkiol1pxs7jc8ijuaabuuucisae719.jpg "/>


How to use a script to complete a copy of a binary program and required library files

#!/bin/bash
Dest=/mnt/sysroot
#复制库文件
LIBCP () {
libdir=${1%/*}
#判断目录是否存在, does not exist the directory is created
[!-D $DEST $libdir] && mkdir-p $DEST $libdir
#判断库文件是否存在, does not exist copy the library file to the specified directory
[!-e $DEST ${1}] && cp ${1} $DEST $libdir && echo "Copy lib $ finished"

}
#复制二进制程序
CMDCP () {

#找到某个命令的二进制文件
Cmd= ' which $ | Grep-v ' ^alias* ' | Grep-o ' [^[:space:]]\{1,\} '
cmddir=${cmd%/*}
#判断这个二进制文件所在目录是否存在, does not exist then creates
[!-D $DEST $cmddir] && mkdir-p $DEST $cmddir
#判断指定目录下是否存在该二进制程序, does not exist copy
[!-e $DEST #cmd] && cp $CMD $DEST $cmddir && echo "Copy command $CMD finished"
#通过ldd命令来找到某个二进制文件所需要的库文件 and generate a list for the For loop use
For BINARY in ' LDD $CMD | Grep-o--color '/.*lib\ (64\) \?/[^[:space:]]\{1,\} ';d o
LIBCP $BINARY
Done
}
#提醒用户输入命令
Read-p ' pelase input command: ' COM
#判断用户输入的命令是否正确
until [$COM = = ' Q '];d o
! Which $COM &>/dev/null && Echo ' command wrong! ' && read-p ' input again: ' COM \
&& continue
CMDCP $COM

Read-p ' pelase input command: ' COM
Done

This article from the "Linux Learning Path" blog, declined reprint!

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.