I'm trying to source a file whose name is passed from stdin. My plan is to create a function like this:
mySource() {
# get stdin and pass it as an argument to `source`
source $(cat)
}
to be called like this: $ echo "file1.sh" | mySource wherein file1.sh is:
FILE=success
export FILE
Assuming $FILE is initialized to hello world, when I run $ echo "file1.sh" | mySource, I expect $ echo $FILE to print success; however, instead it prints hello world.
Is there some way to source a file from a function?
source $(cat)withread file; source $file. That's the usual way to read a word from standard input.