![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| passing strings as arguments | iago | UNIX for Dummies Questions & Answers | 1 | 08-22-2007 07:04 AM |
| Passing and using arguments in Scripts. | David.Vilmain | Shell Programming and Scripting | 1 | 11-13-2006 02:32 PM |
| Passing arguments to a script | Kevin Pryke | Shell Programming and Scripting | 3 | 06-14-2002 06:06 AM |
| Passing arguments to an alias | pmcg | UNIX for Dummies Questions & Answers | 1 | 10-23-2001 08:15 AM |
| passing arguments | jpprial | UNIX for Dummies Questions & Answers | 4 | 04-03-2001 08:13 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
I have an executable that processes under the basic premise of:
Code:
program file_in file_out "parameters a b c" Code:
program file1 + file2 + file3 file_out "parameters a b" Code:
program file1 + file2 + file3 file_out "parameters a b" "parameters a d" My problem is that I need to modify the file permissions on the file_out. When I thought that the first example above was the only way to run, that was easy since I could do a: Code:
FILE_OUT="$2" chmod g+w $FILE_OUT I was thinking of outputting each $variable to a file, grep to exclude the " lines, and then the last line would be my output. However, the following code is not maintaining the " symbols; thus I cannot grep. Code:
NUM_VARS="$#" count=1 while [ $count -le "$NUM_VARS" ] do echo "$count" "$#" "$*" echo "$1" >>$temp_file shift count=$((count+1)) done My output $temp_file looks like: Code:
file1 + file2 + file3 fileout parm1 a b parm2 b d |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Switch files and parmeters
Switch files and parms on the command line since what you have is a non-standard implementation. According to the standard parameters must precede files that are provided on the command line implying that the output file would be the last one on the command line.
|
|
#3
|
||||
|
||||
|
Can't switch the order
The order shown is the order the line must be in. I am trying to front-end an existing executable, and that executable is requiring the input to be laid out in that manner - I wish I could change the order of the input parameters.
But, I must follow the: Code:
program file_in file_out "parameters a b c" |
|
#4
|
|||
|
|||
|
Test for file existence
How about testing for the existence of a file and shifting the command line parameters conditionally??
The input files should all exist (barring typos or errors) but the output file doesn't as it will be created after processing through the executable. Is that a correct assumption?? I modified your while loop based on that premise... Code:
NUM_VARS="$#"
count=1
while [ $count -le "$NUM_VARS" ]
do
if [ ! -f $1 ]; then
OFILE=$1
else
shift
fi
count=$((count+1))
done
echo Output File is $OFILE
|
|
#5
|
|||
|
|||
|
If that's the only file which is created during the execution of this program, maybe you can twiddle your umask
|
|
#6
|
|||
|
|||
|
You can grep the parameters for a space, if you find a space the previous parameter is the output file, something like:
Code:
#!/bin/sh
for i in "$@"; do
if echo "$i" | grep ' ' > /dev/null 2>&1; then
echo file_out = "${out_file}"
fi
out_file="$i"
done
|
|
#7
|
|||
|
|||
|
Using echo | grep is really kind of excessive when you have case
Code:
case $i in *' '*) echo file_out="$out_file";; esac |
|||
| Google The UNIX and Linux Forums |
| Tags |
| recognize parameters with spaces |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|