前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Linux基础 | shell脚本编译成二进制可执行文件

Linux基础 | shell脚本编译成二进制可执行文件

原创
作者头像
凡人学运维
发布2022-06-10 20:12:22
3.8K0
发布2022-06-10 20:12:22
举报

1、安装编译软件,编译后生成shc文件就是命令程序

代码语言:javascript
复制
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

查看帮助手册

代码语言:javascript
复制
[root@localhost shc-3.8.9]# ./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、编写 test.sh 测试脚本

代码语言:javascript
复制
[root@localhost shc-3.8.9]# cat /root/test.sh
#!/bin/bash
echo 'Hello Test!'

3、编译脚本,生成可执行文件

代码语言:javascript
复制
[root@localhost shc-3.8.9]# ./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

4、编译后生成的 /root/test.sh.x 文件就是可执行文件

代码语言:javascript
复制
[root@localhost shc-3.8.9]# /root/test.sh.x
Hello Test!

END

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档