When you speak
echo $var1 $var2 $var3 > ./test.txt
You echo ing var1, var2 and var3 into the test.txt file, which is located in the same directory as the script that runs it.
So, if you are in /var/www , the execution of echo $var1 $var2 $var3 > ./test.txt will be the same as for echo $var1 $var2 $var3 > /var/www/test.txt .
The problem you are facing is this error:
./test_bash.sh: line 13: ./ test.txt: Permission denied
This tells you that you are not allowed to write to the /var/www/test.txt file. To do this, change the write permissions to this file so that "others" can be written to it (that is, the www or apache user):
chmod o+w /var/www/test.txt
Or perhaps better, write to another directory. For example /tmp .
Finally, note that it is recommended that you quote your var . So itβs better to say:
echo "$var1 $var2 $var3" > test.txt
fedorqui
source share