Reputation: 757
My project structure:
/Users/user1/home/bashScrpts/shellScript.sh
/Users/user1/home/pyScrpts/pyScrpt.py
From the shell script I want to call a function of pyScrpt.py
Content of pyScrpt.py
def test():
return sys.argv[1]
shellScript.sh
DATA="testXX"
cmd="import sys;sys.path.insert(0, '/Users/user1/home/pyScrpts/pyScrpt');import pyScrpt; print pyScrpt.test()"
xy=$(python -c \'${cmd}\' "${DATA}")
echo $xy
Error I am getting:
File "<string>", line 1
'import
SyntaxError: EOL while scanning string literal
I don't see whats going wrong here.
Can anyone help me on this??
Upvotes: 0
Views: 89
Reputation: 461
You just need to replace \'
in \'${cmd}\'
with double quotes "${cmd}"
.
Also you should add import sys
to your pyScrpt.py
.
Upvotes: 1
Reputation: 159
I have never done this before, but i would hazard a guess that it may be due to the wrong function structure, it should read:
def test()
return sys.argv[1]
Upvotes: 0