For loop question
Good Morning Guys,
I have a quick question regarding a for loop I'm constructing. I need to get an output filename from an existing file by removing the last part of the file extension and then use that as an output filename in a decryption command. I've got the following: Code:
for i in $FILES; The first command works and returns the same filename with an extension of .csv - however I can't seem to store that filename in a variable... I need to put something at the end of the GPG command --output to give the decrypted file the name .csv For example, $FILES may contain the following files: 230614093023.csv.pgp 230614101435.csv.pgp My loop needs to decrypt the above files, and name the output the same as above but without the PGP. I tried decrypting without an output filename thinking it may do it that way as standard, but it seems to require an output filename. I'd be as always really grateful for any advice :) Thanks Jon |
I not sure if it is homework. but following may work...
Quote:
|
instead of
for i in `ls` use for i in * but they are not really safe. Is that what you really want? output filename can be generated as ${i%.pgp} basename can be calculated by ${i##*/} |
Hi,
Thanks for your response. Not sure what you mean by homework? It's not my homework if that's what you mean! lol - I'm just learning BASH and doing a little project to help me learn. So I took your idea and adapted it slightly but it still does not do work in the way I hoped, however I think we're closer: Code:
for i in $FILES; do |
Ahh that's done it.
The following appears to work fine: Code:
for i in $FILES; do |
see man bash, parameter expansion or here: http://wiki.bash-hackers.org/syntax/pe, substring removal
(and don't forget to press YES if you really want to say thanks) |
All times are GMT -5. The time now is 09:12 AM. |