I've installed a version of Ubuntu Server and although I'm fairly still fresh with Ubuntu, I'm trying to create a bash file to run a program in the background. More importantly, I'm trying to get a file nameto display correct and create it before I start running the program (I like my debug stuff).
However, here is my bash script:
#!/bin/bash
PATH="/var/log/servers/Game/"
FILENAME="startup"
EXT=".log"
DATE=$(date +%d-%m-%Y)
NEWFILE=${PATH}${FILENAME}_${DATE}${EXT}
I have verified that the file does exist in the PATH directory. However, the issue is with the date command. When I run the script bash -x game.sh
this is what is displays.
+ PATH=/var/log/servers/Game/
+ FILENAME=startup
+ EXT=.log
++ date +%d-%m-%Y
game.sh: line 5: date: command not found
+ DATE=
+ NEWFILE=/var/log/servers/Game/startup_.log
+ echo /var/log/servers/Game/startup_.log
I don't understand why it would say the command doesn't work, when I can go to the main console and run date
and get a valid response.
Any help is greatly appreciated!
Best Answer
This sets the
PATH
to just that directory, and I doubt that directory containsdate
.Be careful when you use uppercase variable names, you could easily be stomping over a standard environment variable.
Stick to lowercase, and be more descriptive. Consider using, for example: