Execute shell script in a zip archive

こ雲淡風輕ζ 提交于 2019-12-13 03:52:48

问题


I have a huge folder in a Linux system. Within it, I have a zip archive that encloses a couple of shell scripts. I need to execute these shell scripts, but the challenge is that I don't have write access to this folder. Also, I cannot move it to other directory either, since the location of this file is critical to its execution. It won't work in any other directory.

Is there any way to execute the shell script from within the zip archive without extracting it?


回答1:


You can unzip one specific file by just specifying the path after the zip file:

$ unzip c.zip a.sh
Archive:  c.zip
 extracting: a.sh 

In this command a.sh is the path to the script you want to run.

You can print the contents to stdout with the -p parameter:

$ unzip -p c.zip a.sh
#!/bin/sh

echo "this is a.sh; it is now $(date)"

And finally you can then pipe this to sh to run it:

$ unzip -p c.zip a.sh | sh
this is a.sh; it is now Tue Sep 26 11:02:28 BST 2017

Note that quite a few shell scripts assume bash, so you may want to pipe it to bash instead of sh, depending on the script.



来源:https://stackoverflow.com/questions/46423291/execute-shell-script-in-a-zip-archive

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!