Created
February 17, 2022 22:19
-
-
Save cbillowes/846d2c9c6466ac49337c7b7a097c6ec5 to your computer and use it in GitHub Desktop.
Read from files
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 | |
# places to read files from | |
paths=("../src/themes/**/index.js" "../src/themes/base.js") | |
rm -rf ./tmp/themes | |
mkdir -p ./tmp/themes | |
# this was an experiement to add dynamic files for tests | |
# in Storybook. | |
# reads files from all locations in $paths | |
for story in ${paths[@]}; do | |
if [ -f "$story" ]; then | |
temp=./tmp/$story | |
# examples of ways to manipulate the filename | |
# with replacing text in the filename | |
temp="${temp/\.\.\/src\//}" | |
temp="${temp/\/index\.js/.js}" | |
# read story into the variable | |
body="$(<$story)" | |
# write the variable into the new file | |
echo $body > $temp | |
echo "Wrote $story to $temp" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment