0

I would like to have an alias with an argument to split similar commands, is there a way for this to be possible:

alias vault -e="ansible-vault edit vault.yml"
alias vault -v="ansible-vault view vault.yml"
Zeitounator
  • 38,476
  • 7
  • 53
  • 66
BICB4
  • 1
  • 1
  • 4
  • Short answer: you can't. You can add options to an alias that will be appended to the aliased command. But you can't have an alias specific option that will launch a different command. Create 2 aliases e.g. `vault-e` and `vault-v` – Zeitounator Mar 07 '22 at 10:29
  • Use a function instead. Because answers were disabled while I'm writing one, I put the code here: `function vault { if [[ $1 = -e ]]; then ansible-vault edit vault.yml; elif [[ $1 = -v ]]; then ansible-vault view vault.yml; else printf "Usage: vault -e|-v" >&2; fi } ` – Wiimm Mar 07 '22 at 10:31
  • Zeitounator that is how I currently have but I was interested in this option, @Wiimm thank you very much, will try that – BICB4 Mar 07 '22 at 10:38

0 Answers0