I have this command in a shell script and I can get it to echo ok, but when I try to execute the command I get a "file not found" error. Which is strange because, if I copy and paste the same command at the cli it works ok.
It's probably failing to fine ./executable could the working directory be different in the script? I'd suggest putting a full path to the "executable" file.
You seem to have some issues with quoting here, what does the final quote on your command match?
>\ /send
This is trying to create output under folder " /send", i.e. a directory name "send" under a directory with a single space as its name (" ") in the current directory.
How will I read the options (O1,O2,O3) to the command if I do it this way?
---------- Post updated at 11:39 PM ---------- Previous update was at 10:42 PM ----------
Ah, I see what you're saying. The problem is "O1 O2 O3" are literal stings that must go with the command. Let me play around with this a little to see if I can come up with something.
Nah. That doesn't appear to be working. Although all the errors have gone away, it's not running the ./executable or logging to the log directory. The end command has to be "O1 O2 O3 ./executable ..."
---------- Post updated at 11:13 AM ---------- Previous update was at 12:22 AM ----------
I've tried a few options but I can't get this to work.
I agree with you, however I can't figure out where I'm messing up. I need the quotes because the literal command string is so strange.
Here's the exact command I'm trying to do in the script.
The command has to be that way (with the single quotes and everything).
Because the O1 value will be the only value that will change, I need the extra quotes to ensure the O1 value gets input exactly as O1='input value'.
The problem I think I'm having is the environment is looking at 'O1=' as something it should be substituting, however, there is no associated value. I need to be able to call the exact sting as one literal string and execute that.
Because frankly you've got some fundamental misunderstandings about how quotes work in shell.
You don't "need the extra quotes". They're what's stopping it from working. Have a look at what quotes do:
$ "cat /etc/passwd"
sh: cat /etc/passwd: not found
$ cat /etc/passwd
root:x:0:0:root:/home/root:/bin/sh
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
...
$ # Things inside single quotes do not substitute. echo '$VAR' prints $VAR, not asdf.
$ VAR=asdf
$ echo '$VAR'
$VAR
$ echo "$VAR"
asdf
$ Extra quotes to 'protect' it stop it from working
$ "A=B C=D E=F" echo asdf
sh: A=B C=D E=F: not found
$ # It's supposed to work like this
$ A=B C=D E=F echo asdf
asdf
$ # You can quote the individual parts as you please, but not the whole thing:
$ A="B" C="D" E='F' echo asdf
asdf
$
Putting the whole expression inside quotes will prevent it from splitting, causing the shell to take it as some strange filename and complain about no such file being found.
The quotes I used are exactly what is necessary. The quotes you replaced it with break it, because variables do not expand inside single quotes.