Skip to content

Instantly share code, notes, and snippets.

@rg3915
Created February 3, 2024 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rg3915/863894242c58d35323d37de9bdd1dcb8 to your computer and use it in GitHub Desktop.
Save rg3915/863894242c58d35323d37de9bdd1dcb8 to your computer and use it in GitHub Desktop.
Create one folder and files inner this folder with Shell script. Create folder and files with Shell script.
#!/bin/bash
: << 'COMMENT'
Create one folder and files inner this folder.
Example
$ source teste.sh "folder1/{file1.txt,file2.txt}" "folder2/{file3.txt,file4.txt}"
COMMENT
for string in $*; do
folder=$(echo "$string" | awk -F'/' '{print $1}')
inner_part=$(echo "$string" | awk -F'/' '{print $2}' | sed 's/{\(.*\)}/\1/')
echo "Folder: $folder"
echo "Files: $inner_part"
IFS=',' read -ra files <<< "$inner_part"
mkdir -p $folder
for file in "${files[@]}"; do
touch $folder/$file
done
done
tree
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment