I have a simple bash script template file that I use to generate new bash scripts from python. Each time I change some values in a variable and then create a new copy of the template from python. After saving the file, I give it executable permission. Let me mention it now that I'm using pycharm as the editor. But when I run this newly generated bash script from the terminal it always gives me the following syntax error:
./job_load_8.sh: line 4: syntax error near unexpected token `('
When I open this newly created bash script file in pycharm and comment all echo statements and save the changes, then the script doesn't throw any errors. And when I go back and uncomment all my previously commented statements, then the script works exactly as expected. Clearly, pycharm is doing some auto-formatting that I'm missing. What is happening here ?
Edit: After many people pointed out that I haven't delved sufficient information, I'm giving more details now. Although, I have solved my issue, I'm mentioning more details in case someone else faces this issue and wants an answer.
Here is the python code that inserts certain lines in the bash script:
# at line number 11, insert a variable GPU_FLAG
lines.insert(11, "gpuFlag = " + str(gpu_flag) + "\r")
# at line number 12, insert a variable NUM_ITER
lines.insert(12, "gpuFlag = " + str(gpu_flag) + "\r")
# get the last set of spot file names from the cohort and save them in a list called spot_file_names separated by commas and add a newline
lines.insert(13, "spotFileNames = [" + ", ".join(["'" + spotFileNames[spot_cohort*(i//spot_cohort)+k] + "'" for k in range(i%spot_cohort+1)]) + "]\r")
And shown below is the result of diff between the two scripts, i.e., before and after commenting and uncommenting.