Wednesday, November 17, 2010

How to change directory in Ubuntu / Linux?

Whenever I open my gnome-terminal, I usually always need to switch to a sub-folder. so I created a file named ';s'; with contents



#! /bin/bash

cd my_subfolder



gave it execute permission, but now when I type ';./s'; in my console, it does nothing! But accidentally one day I typed ';. s'; instead of ';./s';, and it changed PWD to my_subfolder! (Which I was expecting from command ./s).



so now my question is what is the difference between commands ';./s'; and ';. s'; ? I'm using gnome-terminal on Ubuntu 8.10, shell is bash.

';man .'; returns nothing by the way nor ';man \.';.How to change directory in Ubuntu / Linux?
When you execute a shell script using the following syntax:



./s



Bash forks another shell, with the same environment that is used in your current shell. However, it doesn't affect your current environment, which is why your directory isn't changed. The dot command means that the script will be interpreted directly by the current shell, without forking a sub-shell. If the script makes changes to the environment, it is your current shell's environment that is changed.

No comments:

Post a Comment