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
  • 713,503
  • 59
  • 514
  • 593
ytbryan
  • 2,524
  • 27
  • 42

1 Answers1

1

You can do like this:

$ eval $x
yolenoyer
  • 7,831
  • 2
  • 24
  • 53
  • 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