Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create a multi variable nested directory structure UNIX

Trying to create a nested directory structure YEAR/FILE_TYPE.

Desired Directory Structure:

~/2016/doc
~/2016/pdf
~/2016/txt
~/2015/doc
~/2015/pdf
~/2015/txt

etc...

create by YEAR variable with: set varYear (seq 1996 2016) # fish shell syntax

create File Type variable set varType (doc pdf txt) # fish shell syntax

1st failed attempt: running echo "mkdir /"$varDate/$varType

2nd failed attempt: for i in $varDate echo $i "/" $varType end # fish shell syntax

Would appreciate some help on how to combine the two variables together in a for loop to create the directory structure.

like image 938
David Sadler Avatar asked Mar 23 '26 05:03

David Sadler


1 Answers

$ set years 2015 2016
$ set subdirs doc pdf txt
$ echo {$years}/{$subdirs}
2015/doc 2016/doc 2015/pdf 2016/pdf 2015/txt 2016/txt

Just replace echo with mkdir -p.

See https://fishshell.com/docs/current/index.html#expand-variable
and https://fishshell.com/docs/current/index.html#expand-brace

like image 149
glenn jackman Avatar answered Mar 26 '26 13:03

glenn jackman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!