在python中是新的。 我创build一个Python脚本,返回一个stringhello世界。 并创build一个shell脚本。 从shell添加一个调用到python脚本。
我需要从shell传递参数到python。
我需要在shell脚本中打印python的返回值。
这是我的代码
shellscript1.sh
#!/bin/bash # script for tesing clear echo "............script started............" sleep 1 python python/PythonScript1.py exit
PythonScript1.py
如何编写脚本在后台运行多个进程,并在每个单独的命令完成后运行其他命令?
保存cron作业的rsync密码
当我在Bash脚本中使用&function时会发生什么?
不能得到这个简单的sed命令
除了某些文件的tar / gzip
#!/usr/bin/python import sys print "Starting python script!" try: sys.exit('helloWorld1') except: sys.exit('helloWorld2')
复制,然后在Bash中asynchronous移动文件
scp:如何找出复制完成
在unix / linux命令行(例如BASH)中定义函数
您不能将消息作为退出代码返回,只能是数字。 在bash中可以通过$?访问$? 。 你也可以使用sys.argv来访问代码参数:
import sys if sys.argv[1]=='hi': print 'Salaam' sys.exit(0)
在shell中:
#!/bin/bash # script for tesing clear echo "............script started............" sleep 1 result=`python python/PythonScript1.py "hi"` if [ "$result" == "Salaam" ]; then echo "script return correct response" fi
像下面这样将命令行参数传递给Python脚本:
python script.py $1 $2 $3
打印这样的返回代码:
echo $?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。