简体   繁体   English

如何通过python代码创建shell脚本?

[英]How can I create a shell script through a python code?

I have written a python code inside which at a certain line I want to write a file xyz.sh but its saying permission denied.我写了一个 python 代码,在其中的某一行我想写一个文件 xyz.sh 但它说权限被拒绝。 I tried to use os.rename() also but it didn't work.我也尝试使用 os.rename() 但它没有用。 Thanks in advance.提前致谢。

Since we don't know your code, we can't give an exact answer.由于我们不知道您的代码,因此我们无法给出确切答案。 But here are some hints:但这里有一些提示:

If you are new to linux, you may want to check that if you want to use a relative path, you are not allowed to start the path with a / at the beginning.如果你是新来的Linux,你可能要检查,如果你想使用相对路径,你不能用一个开始的路径/开头。

Further we don't know which part fails (execution or writing).此外,我们不知道哪个部分失败(执行或写入)。 If execution fails check that:如果执行失败,请检查:

Before execution your file has to be marked as executable.在执行之前,您的文件必须标记为可执行文件。 In the command line you could do: chmod +x xyz.sh在命令行中,您可以执行以下操作: chmod +x xyz.sh

If you want to execute a relative path you have to start the path with a ./ at the beginning.如果要执行相对路径,则必须以./开头。 (ie ./scriptsInMyProgramFolder/xyz.sh ) (即./scriptsInMyProgramFolder/xyz.sh

Please be a bit more precise next time.下次请准确一点。 ;-) ;-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM