Simple bash script problem

#!/bin/bash

cd /media/disk-2

Running

./run.sh

it's not changing directory.Why?

It should change to what?
I expect that if you typed running than it changed, no?

So how can i change the directory running a script?

try typing the same thing in the command prompt and check if its changing or not, then you would probably figure out what has went wrong, if it does not change dir.

From terminal it works:

/bin/bash
cd /media/disk-2

So why doesn't work from script?

source your script:

. ./run.sh

It runs in a subshell.

1 Like

Nice.