In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to create binary files from shell scripts, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
When using the Linux system, we all use a lot of commands. Most commands are available in / bin, / sbin, / usr/bin, / usr/sbin, and so on in binary format. As system administrators, we write a lot of shell scripts to accomplish some tasks or automate them.
This article will introduce you to creating binaries for shell scripts, because no one can see the source code of the scripts, and we can use them as commands. To create binaries from scripts, we use the SHC compiler.
Follow these steps to do this.
Step 1: prerequisites
First, you need to install the required packages for the SHC compiler.
For Ubuntu,Debian and LinuxMint
$sudo apt-get install libc6-dev
For CentOS,RHEL and Fedora
$sudo yum install glibc-devel
Step 2: download and install SHC
Download the latest source code from the SHC compiler's official web page or use the following command and extract it on your system.
$cd / usr / src$ wget http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.9.tgz$ sudo tar xzf shc-3.8.9.tgz
Now compile the SHC source code on your system and install it using the following command.
$cd shc-3.8.9$ make$ make install
Step 3: create a shell script
Let's create a shell script based on our requirements, or skip this step if we have already done so. For this article, we have created the following example script that adds the integer values given on the command-line arguments and shows their sum.
Vim script.shrunchbinbinapash bashtotalcards 0 for I in $@; do if [!-z "${ionization # [0-9] *}"]; then echo "Please enter numeric only" exit 1 fi total=$ (($total + $I)) doneif [$total-eq 0]; then echo "Plesae execute script like: $0 10 20 30" exit 0fiecho $total
Step 4: create a binary file for the script
At this stage, we have installed the SHC compiler and have a shell script called script.sh. Use the following command to create a binary for the script.
$shc-T-f script.sh
The above command creates two files in the current directory. One of them is script.sh.x.c, which is the C language format in the script. The second is script.sh.x, which will be in binary format.
Step 5: test the binary script
If you try to open a script in binary format, you will see that it is not a readable format.
Now move the script to the / usr/bin directory so that it can be used anywhere on the system. Also remove .sh.x from the file name. Therefore, it will be implemented under a simple name. Set execution permissions for everyone at the same time
$mv script.sh.x / usr / bin / script$ chmod + x / usr / bin / script
Now enter the command 'script' from anywhere in the system. You will see the same results as the shell script.
Script 10 20 30 60 and above are all the contents of the method of creating binaries from shell scripts. Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.