0

I'm generally having success running shell scripts in Git Bash, but this one runs but does nothing:

#!/bin/bash

cd c:/inetpub/wwwroot/electronWork

What have I missed?

2 Answers 2

2

How are you running the script? If you invoke it like ./script.sh it will create a sub-shell, and change to that directory inside your sub-shell, then exit. If you run it using source ./script.sh it will run the script inside the current shell and change directory there (which I assume is what you want).

Sign up to request clarification or add additional context in comments.

Comments

1

Is that the whole script? If so, then it's probably working fine, changing to the directory, then exiting back to your parent which didn't do the cd.

Have it do something, like pwd and/or ls -l so that you can see it worked, though when it's done it still won't have changed the directory of the caller.

To do that you need to source it as Alex Stiff said.

. whateverYourScriptIsNamed

That would actually make the commands in the file be executed in your context instead of as a subshell.

I think what you may want instead, though, is an alias:

alias eWork='cd /c/inetpub/wwwroot/electronWork'

then you type eWork and it changes your dir.

If you need anything more elaborate that requires arguments, write a function, but you can look that up. ;)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.