Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

/bin/sh: pushd: not found

Tags:

linux

I am doing the following inside a make file

pushd %dir_name% 

and i get the following error

/bin/sh : pushd : not found 

Can someone please tell me why this error is showing up ? I checked my $PATH variable and it contains /bin so I don't think that is causing a problem.

like image 384
Pein Avatar asked Mar 04 '11 11:03

Pein


People also ask

What is pushd in shell script?

The pushd command is used to save the current directory into a stack and move to a new directory. Furthermore, popd can be used to return back to the previous directory that is on top of the stack. It is very useful when we have to switch between two directories frequently.

What is CMD pushd?

The pushd command stores a directory or network path in memory so that it may be accessed at any time.

How do you use Pushd and Popd?

The popd CommandTo change the directory, do something, and then hop back to the previous directory, you can use pushd and popd together. We'll use pushd to move to a different directory. We'll use popd to discard the topmost directory in the stack and move to the directory in the second position.

What does Pushd and Popd?

pushd adds a directory to the top of the stack and popd removes a directory from the top of the stack.


1 Answers

pushd is a bash enhancement to the POSIX-specified Bourne Shell. pushd cannot be easily implemented as a command, because the current working directory is a feature of a process that cannot be changed by child processes. (A hypothetical pushd command might do the chdir(2) call and then start a new shell, but ... it wouldn't be very usable.) pushd is a shell builtin, just like cd.

So, either change your script to start with #!/bin/bash or store the current working directory in a variable, do your work, then change back. Depends if you want a shell script that works on very reduced systems (say, a Debian build server) or if you're fine always requiring bash.

like image 179
sarnold Avatar answered Sep 19 '22 15:09

sarnold