myfile.sh
#!/bin/bash
echo -e "\n starting python script"
python main.py arg1
echo -e "\n done"
This is not working.
Above file has given following error
starting python script
Traceback (most recent call last):
File "main.py", line 97, in <module>
main()
File "main", line 80, in main
header = "arg1: {}\n\n".format(sys.argv[1])
ValueError: zero length field name in format
done
main.py
...
...
def main():
""" main function
"""
header = "arg1: {}\n\n".format(sys.argv[1])
...
...
if __name__ == "__main__":
if len(sys.argv) == 2:
main()
else:
print "\n Invalid no. of arguments"
print "\n Usage:"
print "\n python {} <date>\n".format(sys.argv[0])
exit(1)
Whats the correct syntax to call a python script having arguments from shell script ?