0

I am trying to set the following alias:

alias dash_token="echo $(kubectl -n kubernetes-dashboard get secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}') -o json | jq -r ".data.token" | base64 -d)"

The problem is - when I run this command it executes the right side right away and assigns the result to the alias, instead of assigning the command. What am I doing wrong?

Andrey
  • 187
  • 2
  • 9
  • Use a function rather than an alias. Also, there's rarely any point to using `echo $(somecommand)` instead of just `somecommand`. – Gordon Davisson Aug 23 '21 at 02:17
  • 1
    (1) Double-quoted `$(…)` is expanded immediately. (2) An alias replaces text with text, it's [not designed to do heavy lifting](https://unix.stackexchange.com/a/30950/108618). (3) [What is wrong with `echo $(stuff)`?](https://superuser.com/q/1352850/432690) – Kamil Maciorowski Aug 23 '21 at 04:31
  • @GordonDavisson - yeah I ended up creating a function. The reason I `echo $(command)` is that this alias/function is meant to just dump the acquired token to the console as a quick shortcut for users – Andrey Aug 24 '21 at 18:55
  • 1
    @Andrey Running the command directly, without the `echo $( )` part, already does that. Output from the command goes to the terminal by default, so adding `echo $( )` doesn't do anything useful. – Gordon Davisson Aug 24 '21 at 19:12

0 Answers0