LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash script - command works directly in command line but not in script (https://www.linuxquestions.org/questions/linux-newbie-8/bash-script-command-works-directly-in-command-line-but-not-in-script-4175474207/)

raoulcousins 08-21-2013 07:28 PM

Bash script - command works directly in command line but not in script
 
When I run my executable code from the command line,

Code:

./optAlg data/1.dat 50000
my program runs fine.

I want to wrap it in a loop in bash.

When I put it in the loop shown below, I get

Code:


./batchRun.sh: line 5: ./optAlg.exe data/1.dat 50000: No such file or directory

(and the same message for all other files in the data folder)

What am I doing wrong?


The code that gives the error:

Code:

#!/bin/bash

for inputFile in data/*.dat
do
  "./optAlg.exe $inputFile 50000"
done


astrogeek 08-21-2013 07:31 PM

Code:

#!/bin/bash

for inputFile in data/*.dat
do
  "./optAlg.exe $inputFile 50000"
done

Is that really optAlg.exe? Or optAlg as first shown?

raoulcousins 08-21-2013 07:33 PM

Ah, you got me. It's cygwin. I wasn't sure if I would get 'no cygwin questions here, it's not actually Linux' but I didn't really want to get into that.

Firerat 08-21-2013 07:37 PM

drop the "s


shell is seeing it as one 'long' command

astrogeek 08-21-2013 07:38 PM

Well hiding the environment is not a good way to ask a question, might be important, so it is best to be honest and complete when asking questions - you get better answers.

I don't know cygwin, but in your example in the first instance where you say it works, it is just optAlg, then when you posted the script code it is optAlg.exe. So are they supposed to be the same? Are they actually different as shown? If different, then make your script the same as the shell command that works.

Looks like Firerat spotted the (other) problem.

raoulcousins 08-21-2013 07:41 PM

It was the quotes. I thought I needed them in order for it to know $inputFile was a variable, but I guess not.

Firerat 08-21-2013 07:43 PM

yeah, really the quotes should be round the $var


All times are GMT -5. The time now is 10:39 PM.