#!/bin/shecho"script python ______________>"
cat << EOF | python# This program adds two numbersnum1 = 1.5num2 = 6.3# Add two numberssum = float(num1) + float(num2)# Display the sumprint('The sum of {0} and {1} is {2}'.format(num1, num2, sum))num = 7# uncomment to take input from the user#num = int(input("Enter a number: "))factorial = 1# check if the number is negative, positive or zeroif num < 0: print("Sorry, factorial does not exist for negative numbers")elif num == 0: print("The factorial of 0 is 1")else: for i in range(1,num + 1): factorial = factorial*i print("The factorial of",num,"is",factorial)EOFecho voili voilou
ce qui donne:
script python ______________>
The sum of 1.5 and 6.3 is 7.8
('The factorial of', 7, 'is', 5040)
voili voilou
# avec cat << EOF
Posté par David Marec . En réponse au message Introduire un script python dans un script shell. Évalué à 3.
en utilisant l'astuce
cat << EOFce qui donne:
J'ai pris des exemples au pif