LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   System Date Command Usage (https://www.linuxquestions.org/questions/linux-newbie-8/system-date-command-usage-931978/)

moony10 02-29-2012 12:45 PM

System Date Command Usage
 
Newbie here and I'm puzzled. I'm sure someone more experienced can help me figure this out.

why did I get the system date command instead of the script?

$ whereis date
date: /bin/date ...
$ echo $PATH
.:/usr/local/bin:/usr/bin:/bin
$ cat > date //; assuming the creation of new data file current working directory. File was not there to begin with;//
echo "This is my own version of date."
<CTRL-D>
$ date
Fri May 22 11:45:49 PDT 2009

Dark_Helmet 02-29-2012 12:54 PM

Quote:

$ cat > date //; assuming the creation of new data file current working directory. File was not there to begin with;//
echo "This is my own version of date."
<CTRL-D>
$ date
A few things:
1. The bash comment character is '#' -- not '//'. That likely doesn't affect the root issue, but just to be clear that you aren't mixing-and-matching different language syntax...

2. You never made your custom date script executable. Unless the script is executable, it doesn't matter whether the file is in your PATH or not.
Code:

chmod u+x name_of_file
3. The proper way to create a script is to start the script with a "shebang" line that tells the system what program is needed to interpret the commands in the file. It looks like you're trying to use bash. So:
Code:

$ cat > date
#!/bin/bash

echo "This is my own version of date."
<CTRL-D>


moony10 02-29-2012 01:06 PM

Hello Dark Helmet

Thank You. That makes sense. And the //; (info in between) was just my way of adding a comment to the question and has no impact to the Linux command being ran. Sorry for that confusion. But your response makes sense and I see now why it wasn't displaying correctly.

Thanks again.


All times are GMT -5. The time now is 11:37 AM.