Skip to content

Instantly share code, notes, and snippets.

@cbillowes
Created February 17, 2022 22:19
Show Gist options
  • Save cbillowes/846d2c9c6466ac49337c7b7a097c6ec5 to your computer and use it in GitHub Desktop.
Save cbillowes/846d2c9c6466ac49337c7b7a097c6ec5 to your computer and use it in GitHub Desktop.
Read from files
#!/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