Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign execute permission to a .sh file in windows to be executed in linux

Here is my problem,

In Windows I am making a zip file in which there is a text .sh file which is supposed to be executed in Linux. The user on the other end opens the zip file in Linux and tries to execute the .sh file but the execute permission is gone. So the user has to do it manually ( like explained here:add execute permission.

How can I in Windows make the .sh executable and add it to a zip file so that when the zip file opens in linux the .sh file still retains its execute permission ( so that user doesn't have to do it manually)

like image 910
C graphics Avatar asked Nov 01 '12 20:11

C graphics


People also ask

How do I give permission to run a .sh file?

We can provide the executable permission by using the below command, chmod +x filename.sh. chmod (Change Mode) - Using chmod we can change the access permissions to file system objects. +x - It makes the file executable.

How do I give permission to execution a file?

Three, what permission; read (r), write (w) and/or execute (x). To add world read and execute permission to a file using the symbolic mode you would type chmod o+rx [filename]. To remove world read permission from a file you would type chmod o-r [filename].


2 Answers

As far as I know the permission system in Linux is set up in such a way to prevent exactly what you are trying to accomplish.

I think the best you can do is to give your Linux user a custom unzip one-liner to run on the prompt:

unzip zip_name.zip && chmod +x script_name.sh 

If there are multiple scripts that you need to give execute permission to, write a grant_perms.sh as follows:

#!/bin/bash # file: grant_perms.sh  chmod +x script_1.sh chmod +x script_2.sh ... chmod +x script_n.sh 

(You can put the scripts all on one line for chmod, but I found separate lines easier to work with in vim and with shell script commands.)

And now your unzip one-liner becomes:

unzip zip_name.zip && source grant_perms.sh 

Note that since you are using source to run grant_perms.sh, it doesn't need execute permission

like image 151
sampson-chen Avatar answered Oct 09 '22 12:10

sampson-chen


The ZIP file format does allow to store the permission bits, but Windows programs normally ignore it. The zip utility on Cygwin however does preserve the x bit, just like it does on Linux. If you do not want to use Cygwin, you can take a source code and tweak it so that all *.sh files get the executable bit set. Or write a script like explained here

like image 41
jmster Avatar answered Oct 09 '22 13:10

jmster