Why does my Bash script say "command not found" when I try to display the date and time?

September 4, 2026 2 answers
Asked by MapleEcho42
I'm behind on a Linux class project and struggling with shell scripting. I wrote a Bash script that should display the current date and time when I run the assigned command, but I keep getting a "command not found" error. I'm starting to feel like I'm just bad at scripting. What should I check?

Answers

QuietOrbit7
Youโ€™re not dumbโ€”youโ€™re probably just still getting familiar with the shell. What exact command are you running, and what does the script contain? The full error message matters. If the scriptโ€™s goal is simply to print the date and time, the basic command is `date`. You can read about its options with `man date`.

MapleEcho42: The last version I tried was supposed to show the date and time when I entered the assigned command, but the shell kept responding with "command not found."

Reply to this answer
CedarPixel19
For a script, make sure the file contains something like `#!/bin/bash` on the first line and `date` on the next. Then either run it with `bash filename.sh`, or make it executable with `chmod +x filename.sh` and run it as `./filename.sh`. If you type only the filename, the shell may not search the current directory and report that it canโ€™t find the command.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions