Hi this is my first time writing bash and I'm trying to practice creating a bash script and am attempting to do the following:

  • Using absolute path the script changes directory to your home directory.
  • Next it verifies whether a subdirectory called project exists. If it does not exist it creates that directory.
  • Next it changes directory moving into the project subdirectory using relative path.

I'm already stuck on the first step:

#!/bin/bashcdif [ -d ./project ]then echo hi it exists!elseecho it doesn't exist!cd project/

I would appreciate if someone could help! thank you so much!

2

Best Answer


cd by itself changes the current working directory to the home directory. See man cd for other uses of this command.

You can use the $HOME environment variable. Bash also recognizes a tilde (~) as home.