Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

LINUX SHELL SCRIPTING IF THEN STATEMENT WITH DATES


  • Please log in to reply

#1
m5fromns

m5fromns

    Member

  • Member
  • PipPip
  • 28 posts
I am curious to know if it is possible to create a simple shell script with an if then statement based on the day of the week. This is what I created and it doesn't seem to work. I am a complete newbie to shell scripting so bare with me. This is what I did. Any feedback would be greatly appreciated. Thanks!

#!/bin/bash

TODAY=$(date +%A)

echo "Today is $TODAY"

if [ $TODAY="Saturday" ]

then

echo "Go back to bed"

else

echo "Get your butt out of bed"

fi
  • 0

Advertisements


#2
m5fromns

m5fromns

    Member

  • Topic Starter
  • Member
  • PipPip
  • 28 posts
Oh wow. Upon further review I noticed I left out the spaces between the = sign. Unbelievable.

#!/bin/bash

TODAY=$(date +%A)

echo "Today is $TODAY"

if [ $TODAY = "Saturday" ]

then

echo "Go back to bed"

else

echo "Get your butt out of bed"

fi
  • 0

#3
Father0fNine

Father0fNine

    Member

  • Member
  • PipPip
  • 29 posts
Yes, and BASH can get very picky about it's spaces at times.
  • 0

#4
Cold Titanium

Cold Titanium

    Trusted Helper

  • Malware Removal
  • 1,735 posts
Yeah, try configuring BIND. Oh Noes!! DNS is broken for the entire network because I forgot to place a period somewhere.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP