<p>Due to <code>minikube</code> issues <a href="https://github.com/kubernetes/minikube/issues/13841" rel="nofollow noreferrer">13841</a> and <a href="https://github.com/kubernetes/minikube/issues/13872" rel="nofollow noreferrer">13872</a> (which I believe to be the same), I have to use <code>minikube</code> 1.23.2.  I try using <code>minikube start --kubernetes-version v...</code> with version 1.24+ but none works (not sure why).  Thus, I cannot use the convenient command <code>kubectl -n ... create token ...</code>.  Seba's answer to this <a href="https://stackoverflow.com/questions/40720979/how-to-access-kubernetes-api-when-using-minkube">question</a> shows how to generate the token with this older <code>kubectl</code> version:</p>
<pre><code>$ export secret=$(kubectl get serviceaccount default -o jsonpath='{.secrets[0].name}')
$ kubectl get secret $secret -o jsonpath='{.data.token}' | base64 --decode
</code></pre>
<p>Apparently, the command is only good for service account <code>default</code>.  How can I rewrite that script so it can be used for other users as follows?</p>
<pre><code>$ export my_script=....
$ my_script another_account
</code></pre>

CaTx
<p>If I'm guessing correctly what you are trying to ask,</p>
<pre><code>#!/bin/sh
secret=$(kubectl get serviceaccount &quot;${1-default}&quot; -o jsonpath='{.secrets[0].name}')
kubectl get secret &quot;$secret&quot; -o jsonpath='{.data.token}' | base64 --decode
</code></pre>
<p>which defaults to <code>serviceaccount default</code> but uses whatever you passed in as the first-command-line argument if you do.</p>
<p>If you save this as <code>ktoken</code>, <code>chmod +x</code> the file, and make sure the directory it's in is on your <code>PATH</code> (perhaps with a symlink), you can run</p>
<pre><code>ktoken
</code></pre>
<p>to run it for the <code>default</code> account, and</p>
<pre><code>ktoken otheraccount
</code></pre>
<p>to run it for <code>otheraccount</code>.</p>
<p>Tangentially, there is no need to <code>export</code> a variable unless you need subprocesses to have access to it.</p>
