1. 安装编译软件,编译后生成shc文件就是命令程序
yum install glibc-devel gcc c++ -y
cd /usr/src
wget http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.9.tgz
tar xzf shc-3.8.9.tgz
cd shc-3.8.9/
make
查看帮助手册
./shc -help
shc Version 3.8.9, Generic Script Compiler
shc Copyright (c) 1994-2012 Francisco Rosales <frosal@fi.upm.es>
shc Usage: shc [-e date] [-m addr] [-i iopt] [-x cmnd] [-l lopt] [-rvDTCAh] -f script
-e %s Expiration date in dd/mm/yyyy format [none]
-m %s Message to display upon expiration ["Please contact your provider"]
-f %s File name of the script to compile
-i %s Inline option for the shell interpreter i.e: -e
-x %s eXec command, as a printf format i.e: exec('%s',@ARGV);
-l %s Last shell option i.e: --
-r Relax security. Make a redistributable binary
-v Verbose compilation
-D Switch ON debug exec calls [OFF]
-T Allow binary to be traceable [no]
-C Display license and exit
-A Display abstract and exit
-h Display help and exit
Environment variables used:
Name Default Usage
CC cc C compiler command
CFLAGS <none> C compiler flags
Please consult the shc(1) man page.
2. 编译脚本,生成可执行文件
./shc -v -r -T -f /root/test.sh
shc shll=bash
shc [-i]=-c
shc [-x]=exec '%s' "$@"
shc [-l]=
shc opts=
shc: cc /root/test.sh.x.c -o /root/test.sh.x
shc: strip /root/test.sh.x
shc: chmod go-r /root/test.sh.x
3. 编译后生成的 /root/test.sh.x 文件就是可执行文件
编译后的 test.sh.x 文件和test.sh 在同级目录下