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

0
5
Asked By MapleEcho42 On

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?

2 Answers

Answered By CedarPixel19 On

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.

Answered By QuietOrbit7 On

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."

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.