In Ubuntu 16.04 xenial with Bash 4.3.48 and LEMP, I've created a comfortability function to create a php info file (to better know my php environment), and then delete it after 2 hours. but I'm having a problem calling that function from terminal.
Steps to reproduce my problem
1) Create a file with a function:
#!/bin/bash drt="/var/www/html" pif() { cat > "$drt"/info.php <<< "<?php phpinfo();" rm "$drt"/info.php | at now + 2 hours } 2) Source that file.
3) Call the function in terminal:
pif Sadly, no file by the name info.php was created for me in /var/www/html. I double checked that.
Here's the full trace for executing the function this way (pif):
+ pif + cat + at now + 2 hours + rm /var/www/html/info.php warning: commands will be executed using /bin/sh job 17 at Fri Apr 6 05:43:00 2018 On the other hand, when I try to create the file not from a function, just by executing:
cat > "$drt"/info.php <<< "<?php phpinfo();" The file is created fine.
My question
Why did direct execution from terminal worked but execution of a function containing the code failed?
Update
1) I do indeed have write permissions to /var/www/html.
2) I sourced the file by:
source myFunctions.sh 3) The output of type -a pif is:
pif is a function pif () { cat > "$drt"/info.php <<< "<?php phpinfo();"; rm "$drt"/info.php | at now + 2 hours }
echo $drtoutputs/var/www/html.echoin front ofrm.