DEV Community

Ojekunle D.H Adetunji (TeeJay)
Ojekunle D.H Adetunji (TeeJay)

Posted on • Edited on

3 2

Making a zsh script

Background:

I have been making small notes about my learnings daily, typically any new thing I learnt. I make a small note about it.
I want to name this note with dates and time(This is for easy find, recollection etc) but I need to also get the date in this format 20210510002211

-- Now, the terminal will readily spew out this date formate with this command
date +%Y%m%d%H%M%S * - try it.*

-- Now I can't keep that in the terminal, hence why i need to make it into a script. give it a fancy name and run quick
What do you need:

-A text editor(I use nano here)

  1. Create a file
#!/bin/bash
# A script that spews out current long date and time
date  +%Y%m%d%H%M%S
Enter fullscreen mode Exit fullscreen mode
  • save the file giving it a fancy name (datum)
  1. Setting Permission
chmod 755 datum       //datum is the fancy name  I'm calling the script
Enter fullscreen mode Exit fullscreen mode



--- The script can run now, try
./datum`

  1. Putting it in my own path
  2. Run echo PATH
    -- It should reveal a the current excutable path on the system
    -- It is good practice to have a special folder for your scripts /bin, create that folder on your home directory.
    Now you will have a this pathe ./bin/datum

  3. We need to add the new path to PATH definition on the .zshsrc file

  4. do nano ~/.zshsrc - You will be able to edit that file now, add the path to the script to the PATH line

  5. save and exit

  6. Now, we need to refresh the zsh files

  7. do source .zshsrc

Now, just typing datum in the terminal should spit out that long date and time

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more