I am trying to write a shell program such that it opens a directory and then adds it into a stack.(This is Task 4-8 from book "Learning the bash Shell by Cameron Newham and Bill Rosenblatt")
First, I create a variable in ".profile.sh" as:
export DIR_STACK=""
This allows to initialize the stack when the system log in. Next, I create a file named "pushd.sh" as:
#!/bin/bash
dirname=$1
DIR_STACK="${dirname:-$PWD}"
cd $dirname
Running this command
>>./pushd.sh directory
should update the DIR_STACK variable and open the directory. But this doesn't work!! I mean when I run
>>echo "$DIR_STACK"
the output is
>>""
Any hint would be appreciated. (Note that the file "pushd.sh" has been executable by chmod)