- 论坛徽章:
- 1
|
本帖最后由 boy010 于 2016-05-20 10:54 编辑
最近在琢磨这么个东西,想将多个shell脚本和相关的文件打包成一个可执行程序,在网上查找了半天,终于发现了一位大神做的一个shell脚本,shell_pack.sh,经试验该脚本可以实现没有参数传入情况下的运行(权限所限不能贴链接,就不贴原贴地址了^^,而且因为脚本有100多行,所以我就贴在附件中了,不直接贴在这里了)。但我现在需要在主脚本执行时,还要传入一个参数,但该脚本没办法实现,不知道该如何修改下,请大神指导下,谢谢!当然如果大神有别的方法可以实现,也请不吝赐教!万分感谢!
shell_pack.zip
(1.07 KB, 下载次数: 88)
举个简单的例子:
当前目录下有三个文件,print.sh在执行时会用到list.sh和1.txt
- [root@localhost test]# ls
- 1.txt list.sh print.sh shell_pack.sh
- [root@localhost test]# cat print.sh
- #!/bin/sh
- echo $1 #我需要传入参数的地方
- echo "#############################"
- cat 1.txt
- echo "##################################"
- echo "list all file in /home"
- ./list.sh
- [root@localhost test]# cat list.sh
- #!/bin/sh
- ls -l /home/
- [root@localhost test]# cat 1.txt
- this is 1st line
- this is 2nd line
- [root@localhost test]#
复制代码 shell_pack.sh是用来打包他们的,也就是我贴的附近中的脚本,运行情况如下:- [root@localhost test]# ./print.sh helloworld #不打包直接运行主脚本,传入参数helloworld
- helloworld # 这里可以打印出我希望传入的参数。
- #############################
- this is 1st line
- this is 2nd line
- ##################################
- list all file in /home
- total 10
- drwx------. 2 root root 16384 Apr 28 2015 lost+found
- drwxr-xr-x. 4 root root 4096 Apr 11 17:01 study
- [root@localhost test]# ./shell_pack.sh -p packed_all.sh -s print.sh list.sh 1.txt
- start packing ..
- list.sh
- 1.txt
- print.sh
- output: packed_all.sh
- [root@localhost test]# ./packed_all.sh helloworld # 希望能实现的目的,打包好的可执行程序也可以接受参数传入。
- begin ...
- unpacking ...
- installing ...
- print.sh # 这里打印出了print.sh, 并不是我所想要的helloworld
- #############################
- this is 1st line
- this is 2nd line
- ##################################
- list all file in /home
- total 10
- drwx------. 2 root root 16384 Apr 28 2015 lost+found
- drwxr-xr-x. 4 root root 4096 Apr 11 17:01 study
- install ok, enjoy!
- [root@localhost test]#
复制代码
|
|