-1

As a beginner of bash script, I wrote a simple script to change the directory. Here it is my source code:

#!/bin/bash

set -x
echo "---------------------START-----------"
cd /home/cocadas/Workspace/carnd/CarND-Behavioral-Cloning-P3

I save it as "start" in the /root folder. I change the property of the file to be executable, and then run it as below. The problem is that the execution command cd doesn't work. What did I miss?

cocadas@cocadas-ThinkPad-W540:~$ ./start
+ echo ---------------------START-----------
---------------------START-----------
+ cd /home/cocadas/Workspace/carnd/CarND-Behavioral-Cloning-P3 cocadas@cocadas-ThinkPad-W540:~$ cd
/home/cocadas/Workspace/carnd/CarND-Behavioral-Cloning-P3
cocadas@cocadas-ThinkPad-W540:~/Workspace/carnd/CarND-Behavioral-Cloning-P3$
TriskalJM
  • 2,393
  • 1
  • 19
  • 20
Hong
  • 526
  • 6
  • 21

1 Answers1

2

Your ./start call creates a sub shell. Run source start or . start (. is an abbreviation of source) instead to execute your script directly in your command line, not in a nested container.

ideaboxer
  • 3,863
  • 8
  • 43
  • 62