Help executing command with options


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help executing command with options
# 15  
Old 04-02-2013
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.

Quote:
O1='$input' O2='data2' O3='data3' ./executable > /send/output/to/log`date`.txt
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.
# 16  
Old 04-02-2013
Please at least try exactly as I showed you -- word for word, letter for letter, keystroke for keystroke -- before telling me it's wrong:

O1="$input" O2='data2' O3='data3' ./executable > "/send/output/to/log`date`.txt"

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:

Code:
$ "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.
# 17  
Old 04-03-2013
You're were right. I removed all the quotes including the quote around the $input and it worked. Thanks a mil for the help and the lesson.
This User Gave Thanks to bbbngowc For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Ls command options

Hi, If I want to list files with names containing a certain letter like " a " using just one ls command, is there any way of doing that? Note that it is containing a letter instead of one of the following (starting, ending with a letter or having the letter in between). what I want is to show... (1 Reply)
Discussion started by: AAAnni
1 Replies

2. Shell Programming and Scripting

Reading command options one by one

Hi, Just some questions on the script below...? Given: bash-2.03$ command -a option1 name1 name2 ParseOptions() { local Len=${#@} local Ctr=2 #always start at 2 local Name=() local Iter=0 while ; do if <- Is this correct? so I can get the $2... (2 Replies)
Discussion started by: h0ujun
2 Replies

3. UNIX for Dummies Questions & Answers

Override options of rm command

How can i override options of rm command ?? and how can i implement my own options when we delete file using rm commad it will not delete file it has to move some folder....plz suggest some solution. (10 Replies)
Discussion started by: arun508.gatike
10 Replies

4. UNIX for Dummies Questions & Answers

Running set options from the command line and bash command

I'm reading about debugging aids in bash and have come across the set command. It says in my little book that an addition to typing set you can also use them "on the command line when running a script..." and it lists this in a small table: set -o option Command Line... (5 Replies)
Discussion started by: Straitsfan
5 Replies

5. Shell Programming and Scripting

Need to disable options from a command

Hi, I am working on a Linux machine. I need to disable 2 options from the available 6 options of a command. For eg. in the "ls" command we have various options like "l ,r, t, a, .... " From this, I need to disable option "a" So when the users type in "ls -a", they should get an error or... (4 Replies)
Discussion started by: aster007
4 Replies

6. Shell Programming and Scripting

Restricting the ls command options

Hi I want the 'ls' command to display only the file size,date modified and name of the file.What i could see with different options is this: $ls -got packagecount.csv $-rwxrwxrwx 1 393137 Aug 21 14:46 packagecount.csv Now what should be my possible... (4 Replies)
Discussion started by: sushovan
4 Replies

7. HP-UX

Linux - HP UX Command options

Just I gone with the script, I found some command's options which are not compatible with " HP-UX ". If I found any alternate commands to the following, most probably I will solve the issue here. 1. " iostat -x " --> this command's option( x ) is not available in HP-UX... (2 Replies)
Discussion started by: pk_eee
2 Replies

8. Shell Programming and Scripting

how to? launch command with string of command line options

my description from another thread... here's my code: #!/bin/bash IFS=$'\n' function OutputName() { input=$1 echo $input input=`echo "$input" | sed -e 's/.//'` input=`echo "$input".avi` output_name=$input } if ]; then echo... (5 Replies)
Discussion started by: TinCanFury
5 Replies

9. UNIX for Advanced & Expert Users

Split Command options

HI! All iam using Split command to split a large .txt file in to smaller files, The syntax iam using split -25000 Product.txt iam getting four output files but not in .txt format but in some other format , when i checked the properties the Type of the output files is Type can any... (7 Replies)
Discussion started by: mohdtausifsh
7 Replies

10. Programming

Executing command line options

Can someone please tell me how to modify/add to this code so that it recognizes UNIX command options (all beginning with "-") and executes the command with options? #include<stdio.h> #include<stdlib.h> int main(int argc, char *argv) { int i; system("stty -echo"); ... (8 Replies)
Discussion started by: Safia
8 Replies
Login or Register to Ask a Question