a script with a for loop

Hi Gurus

I have to write a script which does something like this

/usr/local/gpg2/bin/GPG2 -o arch_696354351_1_23.dbf -d arch_696354351_1_23.dbf.gpg
/usr/local/gpg2/bin/GPG2 -o arch_696354351_1_24.dbf -d arch_696354351_1_24.dbf.gpg
/usr/local/gpg2/bin/GPG2 -o arch_696354351_1_25.dbf -d arch_696354351_1_25.dbf.gpg
/usr/local/gpg2/bin/GPG2 -o arch_696354351_1_26.dbf -d arch_696354351_1_26.dbf.gpg
/usr/local/gpg2/bin/GPG2 -o arch_696354351_1_27.dbf -d arch_696354351_1_27.dbf.gpg

all my arch files would be in /ARCH directory.

I'm not sure what's your question nor your problem, I guess maybe you're looking for something like this?

$ for ((i=23; i<=27; i++)); do echo /usr/local/gpg2/bin/GPG2 -o arch_696354351_1_$i.dbf -d arch_696354351_1_$i.dbf.gpg; done
/usr/local/gpg2/bin/GPG2 -o arch_696354351_1_23.dbf -d arch_696354351_1_23.dbf.gpg
/usr/local/gpg2/bin/GPG2 -o arch_696354351_1_24.dbf -d arch_696354351_1_24.dbf.gpg
/usr/local/gpg2/bin/GPG2 -o arch_696354351_1_25.dbf -d arch_696354351_1_25.dbf.gpg
/usr/local/gpg2/bin/GPG2 -o arch_696354351_1_26.dbf -d arch_696354351_1_26.dbf.gpg
/usr/local/gpg2/bin/GPG2 -o arch_696354351_1_27.dbf -d arch_696354351_1_27.dbf.gpg

i am not sure how will this work.

i could do something like

for i in `ls -l ./*.dbf | grep -v "^gpg"' `
do
/usr/local/gpg2/bin/GPG2 -o $i -d *.gpg
done

but when i run this i get this error
bash: command substitution: line 1: unexpected EOF while looking for matching `''
bash: command substitution: line 2: syntax error: unexpected end of file

the problem is instead of putting -d *.gpg in the GPG2 command i need to have the complete file name including .gpg for example arch_696354351_1_23.dbf.gpg

so -o in the command would take arch_696354351_1_23.dbf and -d would take arch_696354351_1_23.dbf.gpg

for i in *.dbf; do /usr/local/gpg2/bin/GPG2 -o $i -d $i.gpg; done
bash-2.05# for i in *.dbf
do
/usr/local/gpg2/bin/GPG2 -o $i -d $i.gpg
done

usage: gpg [options] --decrypt [filename]

it need the file name correctly

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

My guess:

for i in $( ls *.dbf$ )

Not only is ls unnecessary, but it will break your script if any filenames contain spaces or other pathological characters.

Not that it would work anyway with the dollar sign after .dbf

I think this should work:

for i in *.dbf; do /usr/local/gpg2/bin/GPG2 -o $i -d  ${i/.dbf/.gpg}; done

BTW appsdba.nitin: The loop in you original command was not working because of a superfluous single quote right after the double quote.