1

I have an alias that looks like the following

alias testalias12569537329="echo it works"

My question is: How can I call testalias12569537329 in a shell script by concatenating two strings?

x="testalias"
x+="12569537329" #timestamp
exec $x #command not found

I know that I can directly call testalias12569537329 in the shell script. But I would like to manipulate the timestamp. Thank you!

anubhava
  • 761,203
  • 64
  • 569
  • 643
ytbryan
  • 2,644
  • 31
  • 49

1 Answers1

1

You can do like this:

$ eval $x
yolenoyer
  • 8,797
  • 2
  • 27
  • 61
  • 4
    Calling an alias from a non-interactive shell requires [`shopt -s expand_aliases`](http://stackoverflow.com/questions/1615877/why-aliases-in-a-non-interactive-bash-shell-do-not-work). Otherwise, the script will report: `testalias12569537329: command not found` – Eugeniu Rosca Jul 11 '15 at 17:33