Home > database >  Cd into first available directory in git bash?
Cd into first available directory in git bash?

Time:09-21

I know in Linux you can use cd */ to get into the first available directory, however I need a way to get into the first directory using Git bash. I'm writing bash commands for Github Actions that will be run across Linux and Windows machines, so I need a cross-compatible solution.

Running cd */ on Git bash gives me the error bash: cd: too many arguments.

CodePudding user response:

cd */ does not "get into the first available directory." */ expands to the list of all directories in your current directory, which cd won't accept if there isn't exactly one directory.

You could use an array to capture the list and then cd into the first item in the list:

dirs=(*/)
cd "${dirs[0]}"
  • Related