Running an executable from bash prompt

Hi,

I'm trying to run a program from the bash prompt and I don't understand why it is returning with an error.

Dig is my C program, and it takes in parameters J4, detect, 3 and 0182F98E

var1="cygdrive/c/2i/test fixture/software/mccdaqtest/debug/Dig J4 detect 3 0182F98E"

when I do

"$var1"

it gives me a "no such file or directory" error.

what is the correct way to call this program?

var1="'cygdrive/c/2i/test fixture/software/mccdaqtest/debug/Dig' J4 detect 3 0182F98E"
eval "$var1"

Beware of what goes inside the variable.

Why are you storing the command line in a variable? If it's not absolutely necessary, don't do it. If some of the command is dynamically determined, then put only those components in their own, separate variables.

Regards,
Alister

Does the following work from the command prompt:

cygdrive/c/2i/test fixture/software/mccdaqtest/debug/Dig J4 detect 3 0182F98E

If so, that is the correct way to call the program.

----------------------------

It's something to do with cygdrive and fixture relative paths. Try using absolute paths.

That fundamental error is that the variable is quoted. Since it's quoted, there is no word splitting performed and the variable's entire contents are treated as the command name.

The following ...

x='cmd arg1 arg2 arg3'
"$x"

... is equivalent to running ...

'cmd arg1 arg2 arg3'

... at the prompt. All four words will be treated as the command name.

If the variable is left unquoted, then the space in the pathname will cause a problem. Lose-lose.

Regards,
Alister

Guys, thanks for your help. I'm a complete newbie as shell-scripting. I'm using the cygwin shell to control custom c-drivers running in windows for data-acquisition modules...Anyways, so I tried the solution suggested by @elixir_sinari and it worked. I don't understand why it works, i.e. why the single quotes and why I need to use eval. More broadly, though, I'm trying to understand what @alister is suggesting. This var2 variable is actually part of a script file that I'm developing, it contains the path to my c-driver executable. I'm utilizing this path in a lot of places in my code. Since I may change this location later, I wanted to store it in a variable that can easily be modified later. What is the alternative to this?

Now, further along in my scripting, I have another issue and it is as follows:
I have 3 variable declared

handle=2
digPath="/'cygdrive/c/2i/test fixture/software/mccdaqtest/debug/Dig'"

if I do

var2="$digPath $handle"
echo $var2

I get

/'cygdrive/c/2i/test fixture/software/mccdaqtest/debug/Dig' 2

so far, so good.
but if I do:

var2="$digPath $handle config"
echo $var2

then I get this:

configive/c/2i/test fixture/software/mccdaqtest/debug/Dig' 0

What the dicken's is going on here? Why is my line being overwritten by config
. At first I thought there was a limit to the number of characters per line in bash, but I did google on and found getconf ARG_MAX which returns 32000, so that isn't the issue.

Almost certainly, you've been editing scripts with Microsoft Notepad and ended up with carriage returns inside them.

tr -d '\r' < wingarbage > unixtext

Now, back to the subject at hand, you can't embed quotes inside quotes, they will not be evaluated later unless you shoehorn with eval.