I have a shell file that is pulled from github and built into a zip using TeamCity.

It is typically edited and put into github from a Windows machine.

I need this shell script to be executable upon unzipping. How do I do this? Currently I have to do chmod +x blah.sh


The quickest and easiest solution would probably be to use a shell script that addresses your permissions after running the unzip.

  • Yeah - I guess I was hoping for a way to avoid this. But the unzip is already being run via shell script, so I will just do this! Thanks. – elgabito May 4 '12 at 13:16
#! /bin/bash
#First argument ($1) would be the name of the file to be unzipped
#Second argument ($2) would be where to unzip the files to (absolute path)
unzip $1 -d $2
find $2 -name *.sh -print0 | xargs -0 chmod +x

This would work as long as the files you were wanting to make as executable were always going to be *.sh. Otherwise could always add a third argument ($3) and substitute it for the *.sh but then you would always have to input the name of the file to be made executable for every archive.

  • That would make all the files from the zip u+x though, would it not? Including adding traverse permissions to all directories and execute to non-executable files? – Falcon Momot May 3 '12 at 19:52
  • Very true. The script would go in /usr/bin. Still a kludge but best way I could think of to address the issue. – Rob May 4 '12 at 0:51

You should create the archive with a Unix zip to preserve the Unix attributes.

  • Yes, but I'm not zipping it, TeamCity is. – elgabito May 3 '12 at 18:01

What shell are you using? I know in bash you can define your own commands (via alias), for example once i made a custom command i called cdsee and it took a single parameter (a directory) and cd'd to it, then ls -lah immediately. made it very easy to do my work, as i immediately saw the contents of said folder.

It should, likewise, be possible, and even easy, to make a command that would run the unzip command, and then immediately chmod +x.

Unfortunately, how to pull arguments is escaping me at the moment. But the simplest answer would be to use a linux machine for the originating zip-job, or making your custom command/alias execute the chmod automatically.

  • Having an alias with its own semantic arguments is kind of a kludge. It would very nearly be better to write a small script and place it in /usr/bin or something. – Falcon Momot May 3 '12 at 19:51
  • 1
    it works, and is simple to implement. what's the problem with that? also, i don't entirely know what you're talking about with a small script in usr/bin. an alias is just the solution i know of that would work. – acolyte May 3 '12 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.