I am trying to write a variable into a file and also use the variable as the name of the file itself. Any ideas?
EXAMPLE 1: Filename and content within that file should be "helloworld"
#/bin/bash
OUTPUT="helloworld"
echo $OUTPUT > ~/Desktop/directory/outputs/$OUTPUT.txt
EXAMPLE 2: Filename and content within file should be "hellokitty"
#/bin/bash
OUTPUT="hellokitty"
echo $OUTPUT > ~/Desktop/directory/outputs/$OUTPUT.txt
This should work
You need to tell
bash
where your variable starts and where it ends. You can do this by using"${OUTPUT}"
instead of just"$OUTPUT"
.If you really want to do it that way, just use a 2-step, e.g.: