Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

cd into directory using multiple variables from back script

This script appears useless I know but I’m testing for a final variant. When I call cd using multiple variables. Nothing happens. However, when I echo ${this}${that} it produces the proper text. What do I need to do to drop into the directory correctly from a bash script?

#!/bin/bash

this=/path/to
that=/final/directory

echo ${this}${that}
cd ${this}${that}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Add a echo $PWD after the cd, and you’ll see that your cd does work. But the script runs in its own shell, and when that shell exits, you’re back where you came from.

So you can cd somewhere and do work there as long as you’re in the same script. Any program called from your script after the cd will also run in the directory you cd‘d to.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading