Skip to main content
added 10 characters in body
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 267

I want to customize the functionality of cd command as per my needs.

I definedefined the following function - function cd () { cd "$@" && pushd "$@"; }

The intent of this function is to automatically push the directory onto the stack so that it saves me the effort to manually type pushd . everytimeevery time.

However, the above function is an infinitely recursive function, as the call to cdcd is interpreted to be the function itself and not the cd built-in.

How do I reference the cd built-in in this function?

I know that aliases can be escaped using \. What is the way to escape functions or reference built-ins in a more explicit way?

Note: I do not want to rename my function to anything else.

I want to customize the functionality of cd command as per my needs.

I define following function - function cd () { cd "$@" && pushd "$@"; }

The intent of this function is to automatically push the directory onto the stack so that it saves me the effort to manually type pushd . everytime.

However the above function is an infinitely recursive function as the call to cd is interpreted to be the function itself and not the cd built-in.

How do I reference the cd built-in in this function?

I know that aliases can be escaped using \. What is the way to escape functions or reference built-ins in a more explicit way?

Note: I do not want to rename my function to anything else.

I want to customize the functionality of cd command as per my needs.

I defined the following function - function cd () { cd "$@" && pushd "$@"; }

The intent of this function is to automatically push the directory onto the stack so that it saves me the effort to manually type pushd . every time.

However, the above function is an infinitely recursive function, as the call to cd is interpreted to be the function itself and not the cd built-in.

How do I reference the cd built-in in this function?

I know that aliases can be escaped using \. What is the way to escape functions or reference built-ins in a more explicit way?

Note: I do not want to rename my function to anything else.

Source Link
Kshitiz Sharma
  • 9.1k
  • 22
  • 62
  • 77

How to invoke a shell built-in explicitly?

I want to customize the functionality of cd command as per my needs.

I define following function - function cd () { cd "$@" && pushd "$@"; }

The intent of this function is to automatically push the directory onto the stack so that it saves me the effort to manually type pushd . everytime.

However the above function is an infinitely recursive function as the call to cd is interpreted to be the function itself and not the cd built-in.

How do I reference the cd built-in in this function?

I know that aliases can be escaped using \. What is the way to escape functions or reference built-ins in a more explicit way?

Note: I do not want to rename my function to anything else.