简体   繁体   中英

Cd into first available directory in git bash?

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 .

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]}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM