如何在Windows中将执行权限分配给Windows中的.sh文件 [英] How to assign execute permission to a .sh file in windows to be executed in linux

查看:158
本文介绍了如何在Windows中将执行权限分配给Windows中的.sh文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题,

在Windows中,我正在制作一个zip文件,其中有一个文本.sh文件,该文件应在Linux中执行. 另一端的用户在Linux中打开zip文件,并尝试执行.sh文件,但是执行权限已消失.因此,用户必须手动执行操作(如此处的说明:

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.

我如何在Windows中使.sh可执行文件并将其添加到zip文件中,以便在Linux中打开zip文件时,.sh文件仍保留其执行权限(这样,用户不必手动执行该操作) )

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)

推荐答案

据我所知,Linux中的权限系统是通过这种方式来设置的,以完全防止您试图完成的事情.

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.

我认为您能做的最好的就是为您的Linux用户提供一个自定义的解压缩单行代码,以在提示符下运行:

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

如果需要授予多个脚本执行权限,请编写grant_perms.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

(您可以将chmod的所有脚本全部放在一行上,但是我发现在vim和shell脚本命令中更容易使用单独的行.)

(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

请注意,由于您使用的是source来运行grant_perms.sh,因此不需要执行权限

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

这篇关于如何在Windows中将执行权限分配给Windows中的.sh文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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