I’ve one shell script and inside that script am using one sql.
For example:
Select * from Table where city IN ( ‘Pais’, ‘london’, ‘Sydney’) My doubt is if I want to pass N number of parameters to my shell script so that all could set within IN clause, then how it can be done.
May I know please how can I achieve this? With limited number of parameters I have done but this is new scenario to me.
Updated:
Actual Script
#! /bin/bash echo ID, CITY, SALARY, ACCT_NUM, DATE, AMOUNT > /home/joy/Apple/SMMRY_RESULT.csv m_db unload /home/joy/IPC/target/send/sendFile.dbc -column_delimeter ',' -select "Select * from Table where CITY IN ( ‘Paris’, ‘london’, ‘Sydney’);" >> /home/joy/Output/Output_RESULT.csv var=$? --Line 1 echo ID, CITY, SALARY, ACCT_NUM, DATE, AMOUNT > /home/joy/Apple/SMMRY_RESULT.csv m_db unload /home/joy/IPC/target/send/sendFile.dbc -column_delimeter ',' -select "Select * from Table where DATE IN ( ‘2019-02-01’, '2019-02-02,' '2019-02-03');" >> /home/joy/Output/Output_RESULT.csv var1=$? -- Line 2 if [["$var"==0 $$ "$var1==="]]; echo "" | mailx -a "/home/joy/Output/Output_RESULT.csv" -a " /home/joy/Output/Output_RESULT.csv" -s "IPC DATA Output" '[email protected]' > /dev/null then echo "Script Success and Mail Sent" exit 0 else echo "Script Failed" exit 1 fi Questions:
1) How to give one parameter( clubbing all Dates or Cities at once) to script while running so that It could pass as one value comprises of all dates or cities where all values are enclosed with single quote and comma separated ?
For example sh myScript.sh "AllDatesAsFirstParameter" "AllCitiesAsSecondParameter" 2) How can I restrict my Date parameter with specific pattern else shows error ?
The one I've tried below (Just as an example)
#! /bin/bash echo "My Value: $1" echo "My Second Value: $2" sh myScript.sh One Two Thanks
With limited number of parametersHow did you do it?I’ve created $1, $2 and $3 in IN- exactly how? post the actual code. Believe me, it will help a lot.