As a US Marine Corps veteran and avid Trekkie I can confirm that the term “Aye Captain” is from British nautical etiquette and used in the US Coast Guard, the US Marine Corps and US Navy. The rank structure is borrowed heavily from all US and British Naval terms. https://www.quora.com/How-did-the-phrase-aye-aye-captain-originate
Aye, aye literally means yes, yes. It came from the British Royal navy
hundreds of years ago.
This phrase is used constantly in the U.S. Marines, and the usual form
is “Aye, aye, Sir!”. I uttered it myself many thousands of times as an
enlisted marine.
Note that if you said, “Aye, aye, Captain!” to an officer of any other
rank (in any service branch), you would immediately be in trouble and
under suspicion as a possible impostor. This is because the entire
rank structure is taught in recruit training. The real U.S. military
is quite unlike Star Trek.
It’s used as an acknowledgement of a direct order by a superior,
especially to any officer.
The repeating is done because aboard ship (especially in combat) there
may be a lot of background noise or confusion involved. It repeats so
the person issuing the order knows that the person being ordered to do
something is sure of their responsibility.
Yes, yes would be much harder to hear, and using a conventional phrase
like aye, aye avoids that as well as the possibility of a wink or nod
of the head, so others nearby know that an order was given and
acknowledged, and avoids less respectful acknowledgements like yeah,
or okay. It helps to maintain esprit de corps.