LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-21-2013, 07:28 PM   #1
raoulcousins
LQ Newbie
 
Registered: Aug 2013
Posts: 3

Rep: Reputation: Disabled
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

Last edited by raoulcousins; 08-21-2013 at 07:30 PM.
 
Old 08-21-2013, 07:31 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,253
Blog Entries: 1

Rep: Reputation: 2289Reputation: 2289Reputation: 2289Reputation: 2289Reputation: 2289Reputation: 2289Reputation: 2289Reputation: 2289Reputation: 2289Reputation: 2289Reputation: 2289
Code:
#!/bin/bash

for inputFile in data/*.dat
do
  "./optAlg.exe $inputFile 50000"
done
Is that really optAlg.exe? Or optAlg as first shown?
 
Old 08-21-2013, 07:33 PM   #3
raoulcousins
LQ Newbie
 
Registered: Aug 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
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.
 
Old 08-21-2013, 07:37 PM   #4
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
drop the "s


shell is seeing it as one 'long' command

Last edited by Firerat; 08-21-2013 at 07:39 PM.
 
Old 08-21-2013, 07:38 PM   #5
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,253
Blog Entries: 1

Rep: Reputation: 2289Reputation: 2289Reputation: 2289Reputation: 2289Reputation: 2289Reputation: 2289Reputation: 2289Reputation: 2289Reputation: 2289Reputation: 2289Reputation: 2289
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.

Last edited by astrogeek; 08-21-2013 at 07:40 PM.
 
Old 08-21-2013, 07:41 PM   #6
raoulcousins
LQ Newbie
 
Registered: Aug 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
It was the quotes. I thought I needed them in order for it to know $inputFile was a variable, but I guess not.
 
Old 08-21-2013, 07:43 PM   #7
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
yeah, really the quotes should be round the $var
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Command works when pasted at command line but not as bash script neild Programming 7 09-23-2012 07:30 AM
(BASH) Works on the command line, hangs as a script -- what's wrong? SilversleevesX Programming 17 08-08-2010 10:19 PM
Bash script works from command line, fails from cron cmfarley19 Linux - General 4 08-14-2009 12:24 PM
works on command line but not in bash script tara Linux - General 7 02-09-2009 03:57 AM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration