Edit : actually as @thrig says both ways do work.Mods feel free to delete this question (I can't because it has answers)I have a folder that I want to cd into.for example, suppose I am in /home/yannick and I want to cd into my_folder.Now my problem is when the name of the folder is in a variable.This doesn't work :#doesn't workmy_var=myfoldercd $my_varBut this does :#okmy_var=myfoldercd $my_varWhy is that ?Is there a better way to do it ?
using cd command with a variable
bash;cd command
Both of your examples, as shown, are correct. Please update your question with new information (e.g. are those actually the exact directory names being used?) or provide evidence for the doesn't work claim.bash-4.1$ mkdir my_folderbash-4.1$ my_var=my_folderbash-4.1$ cd $my_varbash-4.1$ pwd/home/jdoe/my_folderbash-4.1$ cd ..bash-4.1$ my_var=my_folderbash-4.1$ cd $my_varbash-4.1$ pwd/home/jdoe/my_folderbash-4.1$ 