Let's say I write the following script:
#!/bin/sh
TEXT="hello"
DIR="test"
FILE="bla.txt"
echo $TEXT > $DIR/$FILE
When running it, I get the following error:
test.sh: line 5: test/bla.txt: No such file or directory
But if change the last line to:
echo $TEXT > $FILE
I don't get the error.
I know I can work around it and do:
FILE_TO_WRITE_TO=$DIR/$FILE
echo $TEXT > $FILE_TO_WRITE_TO
But I don't understand why does the error occur in the first place.
mkdir "$DIR"