Created
February 3, 2024 21:33
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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