I know they already exist -- I'm learning about shell scripts right now and the book gives these as an example. I just wanted to know out of curiosity why the popd function isn't working they way it should.
I know they already exist -- I'm learning about shell scripts right now and the book gives these as an example. I just wanted to know out of curiosity why the popd function isn't working they way it should.
Overriding the function of a shell builtin may itself not work properly. Also, the DIRSTACK variable already exists in bash -- as an array, not a flat string. You really should try them in a shell that doesn't have pushd and popd as builtins, like ksh, or busybox/ash.
Also:
Is this literally as the code has it? That seems odd. When I remove the ' ' it works in busybox ash shell.
Last edited by Corona688; 05-14-2010 at 01:14 PM..
Okay, I got a head of myself with this. I thought the DIR_STACK was a typo in my book and assumed it mean DIRSTACK, but it's not. So I'm starting over again and here's the code from the book, which I put in my .profile. The purpose of this excercise is to implement a stack as an environment variable containing a list of directories separated by spaces.
Now, the book said to put the DIR_STACK="" and export statement into my .bass_profile file which I don't have -- or, if I'm correct it is in fact my .profile file (which is one of the three files UNIX reads, according to the book, when you log in -- as that the same as exiting and opening a new window?)
So, I've copied the code and tried it out -- for example, I tried pushd to my Mail directory in my home directory. This is the result:
why does it include the ' '?
if I try popd I get this result:
I don't need to specify the directory I want to pop, correct?
If I understand the code correctly, the first time I pushd, since the value of DIR_STACK is null, it prints PWD and the two single quotes, preceeded by the name of the directory that follows pushd.
But then, when I try another directory with pushd, like the inbox directory inside the mail directory, the mail directory is gone:
Where did the Mail directory go?
And if I try popd I'll get a similar message
Even though there are deficiencies in the code for now (which the book says there are), I'd like some input as to what's going on -- maybe a step by step explanation of each line -- it may well be that these problems are inherent in the code and will be addressed later in the book.
---------- Post updated at 05:08 PM ---------- Previous update was at 04:55 PM ----------
Okay, I just tried something and changed the ' ' to " " and it worked.
So was that a typo in the book? what do single quotes do as opposed to doube quotes?
or is it supposed to be single quotes and I'm missing something?
---------- Post updated at 05:25 PM ---------- Previous update was at 05:08 PM ----------
another update
I figured out I'm getting the "no such directory error" because there are spaces between the directory names.
---------- Post updated at 07:27 PM ---------- Previous update was at 05:25 PM ----------
Corona --
Yes, that's what's in the book, but I changed them to " " and it worked (I posted this about a couple of hours ago as I write this). I'm guessing that it was a typo. Take a look at my most recent post and tell me what you think about my most recent discoveries about this and tell me what you think.
The book is about the bash shell, by the way.
Last edited by Scott; 05-15-2010 at 07:15 AM..
Reason: Fixed code tag
Howdy,
I'm working through the book LEARN PYTHON THE HARD WAY, Appendix: Command Line Crash Course.
I got to wondering if pushd and popd are really ever used all that much?
Thank you for your insights,
DN (4 Replies)
Hello everyone, finally made these commands working, but I don't know how ti implement the history command for this utility? Anyone? Please please (28 Replies)
I'm looking at a script for a pushd function in my bash book:
DIRSTACK=""
export DIRSTACK
pushd ()
{
dirname=$1
DIRSTACK="$dirname ${DIRSTACK:-$PWD' '}"
cd ${dirname:?"missing directory name."}
echo "$DIRSTACK"
}
Wanted to ask if someone could explain what's... (0 Replies)
Hi All,
im using pushd and popd as below , but im getting different results, it is not consistent.
pushd <DIR>
pkzip <ZIP FILE NAME> *
popd
echo " Hi"
it is going into the DIR as expected and while zipping it, in between it got suspended by itself and executed the remaining step... (1 Reply)
This question is related to pushd and popd. After I have pushed directories, I would like to see what are the contents of the stack currently before I execut e popd. The reason is that many a times we forget (or can get confused when multiple shells are open) what we pushed and would like to first... (4 Replies)
I know that pushd/popd are built into csh, but I'm trying to run a set of 3rd party make files that use sh.
My problem is that sh simply squawks that pushd and popd are not found, then the make dies due to the error.
I've searched the entire system, and they are indeed missing. Evidently SGI... (3 Replies)