0

I am trying to assign a directory name to a variable and use that variable to create and change the directory.

dir_name='tmp'
mkdir $dir_name
cd $dir_name

How to change directory?

enter image description here

muru
  • 207,228

2 Answers2

1

Executing bash test.sh or ./test.sh creates a child bash process to execute your script, with a separate working directory.

You can instead use source test.sh or the shorter equivalent . test.sh to run the script in the existing bash instance and environment.

0

I think it works. I followed the following steps.

user@ubuntu2004:~$ dirname="snap"
user@ubuntu2004:~$ mkdir $dirname
user@ubuntu2004:~$ cd $dirname
user@ubuntu2004:~/snap$ 
AjayC
  • 428