0
#! /bin/bash/

# this is a comment

date=$(date)
list=$(ls -la)

echo "date or list?"

read var

if [[ $var=$date ]]
then
        echo "Today's date: $date"

elif [[ $var=$list ]]
then
        echo "Listing all: $list"

else
        echo "Input not recognized"

fi

I've tried changing the if and elif statements multiple times. I want it to print the date when I type date and print ls -la when I type list.

Cyrus
  • 84,225
  • 14
  • 89
  • 153
jcyber
  • 1
  • 1
  • `[[ $var = "$date" ]]` -- note the spaces around the `=`. (The quotes on the right-hand side are for a more obscure reason: without them, the operation is treated like a glob expression instead of an exact string match; it may be easier just to be in the habit of always using quotes on both sides). – Charles Duffy Feb 02 '23 at 03:51
  • Also, if you want to see if the user entered the exact string "date", you want `[[ $var = date ]]`, not `[[ $var = $date ]]`. – Charles Duffy Feb 02 '23 at 03:53
  • Worked! Thank you Charles!! – jcyber Feb 02 '23 at 21:12
  • BTW, take the title of the question this was closed as a duplicate of as an example to try to use in your own questions in the future -- see how it's very specific to the individual technical problem at hand. Even if you don't understand the immediate cause well enough to write _that_ specific a question, the closer you can get the better your question will be at getting direct attention from folks qualified to answer it. – Charles Duffy Feb 03 '23 at 01:12

0 Answers0