shell - ZSH: Call in-built function from zsh function that uses the same name -


i use zsh , extend in-built cd function. i'd when call cd, changes directly , lists content of directory.

function cd() {     cd $1     ls . } 

i'd have expected code work, turns out, call cd refers function definition, resulting in infinite loop.

is there work-around solve problem, apart choosing different name function?

update

strangely enough, worked

function cd() {     `echo $1`     ls . } 

no idea why.

in order use builtin commands within functions of same name, or anywhere else matter, can use builtin precommand modifier:

function cd() {     builtin cd $1     ls . } 

builtin command tells zsh use builtin name command instead of alias, function or external command of same name. if such builtin not exist error message printed.


for cases want use external command instead of alias, builtin or function of same name, can use command precommand modifier. example:

command echo foobar 

this use binary echo (most /bin/echo) instead of zsh's builtin echo.


unlike functions builtin , command not necessary aliases prevent recursions. while possible use alias in alias definition

% alias xx="echo x:" % alias yy="xx y:" % yy foobar y: x: foobar 

each alias name expanded once. on second occurence alias not expanded , function, builtin or external command used.

% alias echo="echo echo:" % echo foobar echo: foobar % alias xx="yy x:" % alias yy="xx y:" % xx foobar zsh: command not found: xx 

of course, can still use builtin or command in aliases, if want prevent use of alias, or if want use builtin or external command specifically. example:

alias echo="command echo" 

with binary echo used instead of builtin.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -