混合python 和shell的脚本

64 views
Skip to first unread message

Chaos Eternal

unread,
Mar 23, 2015, 12:16:58 AM3/23/15
to sh...@googlegroups.com
我也做个记录

干活的时候遇到这么个需求:需要在启动python脚本的时候做一些环境变量(LD_LIBRARY_PATH等)的设置,由于python不像
guile等支持 #! .... !# 这样的注释,所以没法像guile一样优雅地写
#!/bin/bash
do_some_settings
guile $0 $*
!#
(blah blah)

但是,在python的时候,可以这么写:
#!/bin/bash
""""/bin/true
export LD_LIBRARY_PATH=blah:blah
do_some_thing
python $0 $*
B=" """
do_python_thing

然后给脚本chmod +x 就可以了。

Shell Xu

unread,
Mar 23, 2015, 12:44:51 AM3/23/15
to shlug
这就是我如何混进python队伍里的。。。


--
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN
---
您收到此邮件是因为您订阅了 Google 网上论坛的“Shanghai Linux User Group”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到shlug+un...@googlegroups.com
要查看更多选项,请访问 https://groups.google.com/d/optout



--
彼節者有間,而刀刃者無厚;以無厚入有間,恢恢乎其於游刃必有餘地矣。
blog: http://shell909090.org/blog/

Zoom.Quiet

unread,
Mar 23, 2015, 1:37:12 AM3/23/15
to shlug
混这个字用的好哪!
俺也是从 PHP 圈子混进来的.
> 您收到此邮件是因为您订阅了Google网上论坛上的“Shanghai Linux User Group”群组。
>
> 要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到shlug+un...@googlegroups.com
> 要查看更多选项,请访问https://groups.google.com/d/optout



--
Life's Pathetic, Let's Pythonic! 人生苦短, Python是岸!
俺: http://zoomquiet.io
授: http://creativecommons.org/licenses/by-sa/2.5/cn/
怒: 冗余不做,日子甭过!备份不做,十恶不赦!
KM keep growing environment culture which promoting organization be learnning!

liyaoshi

unread,
Mar 23, 2015, 2:18:02 AM3/23/15
to sh...@googlegroups.com
求跟着混

Chaos Eternal

unread,
Mar 23, 2015, 7:59:43 AM3/23/15
to sh...@googlegroups.com
发现之前写错了
guile的应该是
#!/bin/bash
do_some_settings
exec guile $0 $*
exit 1
!#
(blah blah)

python的应该是:

#!/bin/bash
""""/bin/true
export LD_LIBRARY_PATH=blah:blah
do_some_thing
exec python $0 $*
exit "1"""
do_python_thing

张明源

unread,
Mar 26, 2015, 12:37:44 PM3/26/15
to sh...@googlegroups.com, liya...@gmail.com

Python不是应该用os.env来设定产量吗



发自WPS邮件客戶端

在 liyaoshi <liya...@gmail.com>,2015年3月23日 下午2:18写道:

求跟着混

在 2015年3月23日 下午1:36,Zoom.Quiet <zoom....@gmail.com>写道:
混这个字用的好哪!
俺也是从 PHP 圈子混进来的.

在 2015年3月23日 下午12:44,Shell Xu <shell...@gmail.com> 写道:
> 这就是我如何混进python队伍里的。。。
>
> 在 2015年3月23日 下午12:16,Chaos Eternal <chaose...@shlug.org>写道:
>
>> 我也做个记录
>>
>> 干活的时候遇到这么个需求:需要在启动python脚本的时候做一些环境变量(LD_LIBRARY_PATH等)的设置,由于python不像
>> guile等支持 #! .... !# 这样的注释,所以没法像guile一样优雅地写
>> #!/bin/bash
>> do_some_settings
>> guile $0 $*
>> !#
>> (blah blah)
>>
>> 但是,在python的时候,可以这么写:
>> #!/bin/bash
>> """"/bin/true
>> export LD_LIBRARY_PATH=blah:blah
>> do_some_thing
>> python $0 $*
>> B=" """
>> do_python_thing
>>
>> 然后给脚本chmod +x 就可以了。
>>

Chaos Eternal

unread,
Mar 26, 2015, 1:34:39 PM3/26/15
to sh...@googlegroups.com
影响不了LD_LIBRARY_PATH
Reply all
Reply to author
Forward
0 new messages