Autojump Does Not Work Inside of Bash Script
Created by: mowestusa
I'm a newbie when it comes to bash scripting, so there could be a simple fix.
I have a bash variable that holds the directory name of the working directory where the bash script cd
into during while the script is running. Since I tend to start this script from my home folder, when I exit the script I would like to remain in that working directory.
- Yes, I know that I can do this by either
source bash_script
or by simply executingbash
as the last command in the script. These solutions are less than ideal, so I thought since I have autojump installed on all of my Linux systems I could just use it.
However, when I put the command at the end of my bash_script
j $DIR
I get the error message = line 62: j: command not found
If I change the command to autojump $DIR
I don't get the error "command not found" but it doesn't jump to the directory either.
It seems like this should work, because if I create a bash variable in the terminal just at the command line the following occurs:
DIR=directory_name
autojump $DIR
/$HOME/directory_name #it simply prints out the correct path
j $DIR
/$HOME/directory_name #it prints it out in red and jumps to the correct directory that matches the path
I'm doing this currently on WSL 2 in Ubuntu 22.04, running bash, but I would think this would be the same behavior on all my systems.