I am new to shell scripting and trying to read a list of employee IDs from a text file as part of my first shell script program and pass it to another shell script as it's an argument. In the second script, I am using that argument on a SQL select command with a like operator. But my issue is that the command gets executed as something else.
Contents of first.sh
#!/bin/sh
while IFS= read -r line;
do
/d/ShellScripts/second.sh $line
done < "$1"
Contents of second.sh
#!/bin/sh
EMP_ID=$1
sqlplus -s user/password@//localhost:1521/xepdb1 <<EOF
alter session set current_schema = HR;
set linesize 1000
select * from employees where EMPLOYEE_ID like "\'"%$EMP_ID"\'" ;
select * from employees where EMPLOYEE_ID like %{$EMP_ID} ;
EOF
Contents of list.txt
101
102
103
Command executed in the shell
$ ./first.sh list.txt
Session altered.
"\'"ct * from employees where EMPLOYEE_ID like "\'"%101
*
ERROR at line 1:
ORA-00911: invalid character
}elect * from employees where EMPLOYEE_ID like %{101
*
ERROR at line 1:
ORA-00911: invalid character
I tried to take help from here. I am just trying to execute a normal SQL query using like operator, using shell scripts.