Before I loose my ever-loving-mind, can someone help me determine what I am doing wrong here. This was suppose to be an easy and quick script.
I got a PKI certificate bundle. Here is an shorten truncated example:
-----BEGIN CERTIFICATE-----
+d2dgh
HBc1x3
N0rt/5e
-----END CERTIFICATE-----
There are multiple "-----BEGIN CERTIFICATE-----" and "-----END CERTIFICATE-----" strings in the file.
I echo each line to a file and when the "-----END CERTIFICATE-----" is seen the script will create a new file and keep repeating the process of finding the "END" and creating new files until the input ends.
Here is my simple working script. I usually start scripts out very simple and work towards complexity as I confirm each step:
Code:
#!/bin/bash
while read STRING
do
echo "$STRING" >> certfile1.out
echo "$STRING" # Echoing for testing and watching for END string.
if [ "$STRING" = "-----END CERTIFICATE-----" ]; then
echo END found
exit
fi
done < inputcertfile.crt
As I said I have started out very simple by just trying to output to a file and exit when the END string is found. In my if statement I have tried all sorts of matching syntax such as:
Code:
[[ "$STRING" == "*[E][N][D]*" ]]
[ "$STRING" =~ "-----END CERTIFICATE-----" ]
[[ "$STRING" = "-----[E][N][D]*" ]]
plus a handful of other attempts using = or =~ or == along with single bracket and double bracket attempts.
So what am I missing? Any ideas on grabbing the END string and exiting. I'll fix the file redirection later, I just want the thing to exit.
