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?
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.