How do you "cd" in a script without having to source it?

Home Forums Tech Support How do you "cd" in a script without having to source it?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #67897
    linuxgnuru
    Participant

    so, I have this bash script that I’d like to mkdir $1; cd $1 but after the script ends, you’re back to whatever dir you were previously in. I’ve done some searching and it seems unless you . / source the script, the cd will never work. Anyone have an idea how to not have to source the fucking script?

    #76989
    strider
    Participant

    You can’t because when you run a shell it spawns a new shell which is isolated from your current shell.

    If you don’t want to source your script every time then make it a shell function and source the file in your .zshrc or .bashrc then you can call that function directly. (Examples: https://github.com/strycore/dotfiles/bl … nctions.sh )

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.