shell调用python

rong_p.py

#!/usr/bin/python

import sys
x = sys.argv[1]

def main(x):
    print "%s" %(x)
    y=int(x)*2
    print "%d" %(y)
    return y

main(x)

print "Hello, Python!"; #There is a " " !!!


test.sh

#!/bin/bash

x=41
num=3782

RES=`python rong_p.py $x`
r1=$(echo $RES | cut -d' ' -f1) #x
r2=$(echo $RES | cut -d' ' -f2) #x*2

r3=$(echo $RES | cut -d' ' -f2) #Hello,

r4=$(echo $RES | cut -d' ' -f2) #Python!

echo $r1
echo $r2
#echo $[r1+r2] #num
#echo $r1+$r2 #string

oneline=($r1 $r2)
#echo ${#oneline[@]}
#for i in ${oneline[@]}
for ((i=0;i<${#oneline[@]};i++));
do
  oneline[i]=$(echo "scale=6; ${oneline[i]}/$num" | bc)
  echo ${oneline[i]}

  if [ "${oneline[i]}" = "$x" ]
  then
     oneline[i]=$(echo "scale=6; ${oneline[i]}/$num" | bc)
     #oneline[i]=$[oneline[i]+1]
     echo ${oneline[i]}
  fi
done




你可能感兴趣的:(shell调用python)