How can write a script to change to a given directory but also remember it so that when you do cd it always changes to that directory ?#!/bin/bashsetdir() {    cd $1    # remember the directory we are changing to here so whenever we do cd we go back to this set dir}setdir $1
script to remember dir and always cd to it instead of the root dir
bash;shell script;cd command
Something like the following should work:setdir() {    cd $1    export SETDIR_DEFAULT=$1}my_cd() {    cd ${1-${SETDIR_DEFAULT-$HOME}}}Note that these are functions, not a separate script. You can't do that from a separate script, since it would not be able to affect the parent shell that calls it.If you really want to override cd (please, don't do that), replace cd with builtin cd.