Can I use 'cd' in scripts?

QuestionsQuestions8 SkillsProBasic Files OperationsNov, 18 2025
090

Yes, you can use the cd command in scripts. It allows you to change the current working directory within the script. However, keep in mind that the directory change will only affect the script's execution environment and not the parent shell that invoked the script. If you want to change the directory in the parent shell, you would need to source the script instead of executing it.

Here's an example of using cd in a script:

#!/bin/bash
cd /path/to/directory
# Other commands can follow here

0 Comments

no data
Be the first to share your comment!