如何强制/斌/ bash的跨$ P $的oneliners PTER [英] How to force /bin/bash interpreter for oneliners

查看:98
本文介绍了如何强制/斌/ bash的跨$ P $的oneliners PTER的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与Python使用os.system执行的单行bash命令()

I have a one liner bash command that is executed with python os.system()

for FILENAME in mydir/PRE_*; do echo $FILENAME `printf ${FILENAME:0:12}; printf ${FILENAME:23}`; done;

它通过循环目录中的所有文件和重命名它们,采取字符12-23出了名的。当我和我的服务器登录执行它通过庆​​典,但是当我与Web用户执行它通过蟒蛇它抛出错误的命令工作正常。

It loops through all files in a directory and renames them, to take chars 12-23 out of the filename. The command works fine when I execute it through bash with my server login, but when I executed it through python with the web user it throws errors.

我发现,这是因为网络用户的默认shell是/ bin / sh的,而不是/斌/ bash的。

I found out that this is because the web user's default shell is /bin/sh instead of /bin/bash.

我能够与该用户登录并更改外壳为/ bin / bash的。

I am able to log in with that user and change the shell to /bin/bash.

所以,问题是我可以强制单行不改变默认的shell为用户提供/斌/ bash的执行?

So the question is can I force the one-liner to execute with /bin/bash without changing the default shell for the user?

推荐答案

也许你可以称呼其为:

/bin/bash -c '$cmd'

其中, CMD $ 是完整的命令行。

这篇关于如何强制/斌/ bash的跨$ P $的oneliners PTER的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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