Pete Norris
Pete Norris

Reputation: 1054

Create a shell script to run in bash in OSX

WARNING! Getting pretty basic here guys...

I have a rather elaborate shell script that I wish to create, but am haveing difficulty with the most basic of commands so am struggling to get going.

I want to create a .sh file that I can simply run using BASH - If I place just CD in the file and run in BASH nothing happens, whereas running CD from the terminal obv. gets me home.

Could someone shed some light on this please... I am running OSX

thanks

Upvotes: 0

Views: 343

Answers (1)

Paul Evans
Paul Evans

Reputation: 27567

When you run a script you spawn a new sub-shell, your cd works in that and then you exit back to your orginal shell and your old present work directory - just as thought the cd never happened. If you want to short cut cds use a alias or a function. Something like:

go_dev() {
    cd /my/long/path/to/dev/env/
}

or

alias go_dev='cd /my/long/path/to/dev/env/'

Upvotes: 2

Related Questions