randombits
randombits

Reputation: 48490

php resolve bash alias pointing to script

I am interested in having a bunch of aliases setup that point to a particular script. An example would be:

alias foo='php test.php'
alias bar='php test.php'

in test.php, I want to be able to access $args[0] and have it read foo and bar respectively. Currently as it stands, $args[0] would be test.php.

Is there a way around this in PHP 5.5.x?

Upvotes: 0

Views: 32

Answers (1)

Etan Reisner
Etan Reisner

Reputation: 80992

That's not a php issue. That's a shell issue. The alias is handled by the shell. php doesn't even know it existed.

You would need to use symlinks foo -> test.php and bar -> test.php for this to work I believe.

If you just want to use the alias name as a first argument to the php script you could also use a function instead:

foo() {
    php test.php foo "$@"
}

bar() {
    php test.php bar "$@"
}

Upvotes: 1

Related Questions