I have a python script like below.
# Import necessary libraries and functions
import sys
import traceback
y = '2020'
querysting = "select {} from table where Year={}".format(col_list,y)
df = pd.read_sql(querystring,db)
if __name__ == '__main__':
if len(sys.argv) != 8:
print('Invalid number of args......')
print('Usage: file.py Input_path Output_path')
exit()
_, col_list, FinalDB, final_table, host, dsl_tbl_name, username, password = tuple(sys.argv)
data_load(col_list, FinalDB, final_table, host, tbl_name, username, password)
Now I am calling this python script inside a shell script like below
#!/bin/bash
col_list='id, name, address, phone_number'
FinalDB='abc'
final_table='xyz'
host='xxxxxx.xxxx'
tbl_name='test'
username='USER'
password='test_pass'
python python_script.py ${col_list} ${FinalDB} ${final_table} ${host} ${tbl_name} ${username} ${password}
Now when I run this bash script I am getting Invalid number of args...... error
I am pretty much sure that it is some thing to do with col_list variable being passed to the python script.
Because instead of having columns in a list if I just pass select * in the query and removing col_list variable then I don't get any errors
What am I doing wrong here and how can I resolve this issue.
... "${col_list}" "${FinalDB}" "${final_table}" ...instead of just... ${col_list} ${FinalDB} ${final_table} ...). This is a mostly-duplicate of the question: When is double-quoting necessary?.