You are not logged in.

#1 2014-08-14 07:58:19

maggie
Member
Registered: 2011-02-12
Posts: 255

Bash script change directories on exit and move you there

How can I make my bash script change directories so that when it exits, I will be in that directory?

Let's say I start in my home dir and run this simple one:

#!/bin/bash
echo hello world
if [ -d ~/world ]; then
cd ~/world
exit 0
else
echo error
exit 1
fi

When it exits, I am still in my home dir, not ~/world.

Offline

#2 2014-08-14 08:01:46

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: Bash script change directories on exit and move you there


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2014-08-16 18:34:53

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: Bash script change directories on exit and move you there

What problem are you actually trying to solve?

Do you really need a script to be able to change the directory or are you just trying to create a shortcut that will change directory for you.
If it's the later then bash has built in support for this sort of thing.

Last edited by Slithery (2014-08-16 18:35:09)


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

Board footer

Powered by FluxBB