在 zip 存档中执行 shell 脚本 [英] Execute shell script in a zip archive

查看:61
本文介绍了在 zip 存档中执行 shell 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Linux 系统中有一个巨大的文件夹.在其中,我有一个包含几个 shell 脚本的 zip 存档.我需要执行这些 shell 脚本,但挑战在于我没有对该文件夹的写访问权限.此外,我也无法将其移动到其他目录,因为此文件的位置对其执行至关重要.它不会在任何其他目录中工作.

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.

有没有办法在不解压的情况下从 zip 存档中执行 shell 脚本?

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

推荐答案

您可以通过指定 zip 文件后的路径来解压特定文件:

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 

在此命令中,a.sh 是您要运行的脚本的路径.

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

您可以使用 -p 参数将内容打印到标准输出:

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)"

最后你可以把它传送到 sh 来运行它:

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

请注意,相当多的 shell 脚本假定 bash,因此您可能希望将其通过管道传输到 bash 而不是 sh,具体取决于脚本.

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.

这篇关于在 zip 存档中执行 shell 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆