Hey guys, I was doing some basic bash shell script, as I am new to this, and I can't seem to pass over this error. Here is the code:

#!/bin/bash
echo "Please, type in the day of the week."
read Day

if (($Day="Monday"));then
Monday=date +%d
Tuesday=$(($Lunes+1))
Wednesday=$(($Martes+1))
Thursday=$(($Miercoles+1))
Friday=$(($Jueves+1))
Saturday=$(($Viernes+1))
Sunday=$(($Sabado+1))
else
echo "As updates only occur on Monday, an update will not be necessary yet."
fi

echo "Today date is: "; date +%A,%d" of "%B,%Y
echo "To-do list:"

Anyways, my intention is that If I type Monday, the variables would be assigned, but even if I type Monday, bash interprets it like if I had typed something else, and give me the "As updates only occur on Monday, an update will not be necessary yet." message. Any suggestion? Thanks!

Hello Felipevd!

The problem is actually pretty simple. When doing an 'if' comparison, you want to use square brackets [] instead of parens:

...
if [ $Day="Monday" ]; then
...

I noticed some other issues that you'll probably see after the if statement is 'fixed'.

When you want to execute code in the context of setting a variable, you will need to put it in either:

`backticks`
(the little mark that usually shares the ~tilde key)

OR this notation with the dollar sign and parentheses:

$(some commands here)

I prefer the second method. So for example, your "Monday=date +%d" should be:

...
Monday=$(date +%d)
...

I hope this helps!

Thank you so much, the code and tips gave me the solution to my problem, but off course, as in programming, more trouble emerges. Now, I have advanced a little in my script, and now, another error is shown. Here is the code:

#!/bin/bash
echo "Please, type in the day of the week."
read Day

if [ $Day="Monday" ];then
Monday=$(date +%d)
Tuesday=$(($Lunes+1))
Wednesday=$(($Martes+1))
Thursday=$(($Miercoles+1))
Friday=$(($Jueves+1))
Saturday=$(($Viernes+1))
Sunday=$(($Sabado+1))
else
echo "As updates only occur on Monday, an update will not be necessary yet."
fi

echo "Today date is: "; date +%A,%d" of "%B,%Y
echo "Do you want to add any task for the weekend?"
read Task
if [ $Task = "Yes" ]; then
{
echo "For which day?"
read Dayoftask
if [ $Dayoftask = "Monday" ]; then
echo "What task do you want to add for $Dayoftask ?"
read Whattask
MondayTask1=$($Whattask)
echo $MondayTask1 #Just checking if the script is saving the correct info.
fi
}
fi

It's in line 27, where it gives me this error. "my_script_1: line 27: Prueba: command not found
" It's the part where the $Whattask is saved into a variable, I believe. Anyways, I don't know what's wrong, I followed your recommendation for working with variables and the whole $() thing. Hope I'm making myself clear. Thanks!

Glad we could help!

Using $() is only needed if there is a command you need to execute, like where you are calling the 'date' command.

To just set a variable, you don't need $(). Line 27 should *probably* be more like: MondayTask1=$Whattask

Well, that problem is now gone! But I have a new one now! (Off course I do...) Here is my code:

#!/bin/bash
echo "Please, type in the day of the week."
read Day

if [ $Day="Monday" ];then
Monday=$(date +%d)
Tuesday=$(($Monday+1))
Wednesday=$(($Tuesday+1))
Thursday=$(($Wednesday+1))
Friday=$(($Thursday+1))
Saturday=$(($Friday+1))
Sunday=$(($Saturday+1))
else
echo "As updates only occur on Monday, an update will not be necessary yet."
fi

echo "Today date is: "; date +%A,%d" of "%B,%Y
echo "Do you want to add any task for the weekend?"
read Task
if [ $Task = "Yes" ]; then
echo "For which day?"
read Dayoftask
	case $Dayoftask in
"Monday" | "monday" ) echo "What task do you want to add for $Dayoftask?" 
read Whattask
		if [ -n ${Tasksarray[@]} ]; then
Tasksarraylength=${#Tasksarray[@]}
Tasksarray[${Tasksarraylength}+1]=$whattask
echo "${Tasksarray[${Tasksarraylength}]"
else
declare -a Tasksarray
Tasksarray[0]=$whattask
		fi
;;
"Tuesday" | "tuesday") echo "What task do you want to add for ${Dayoftask}?"
;;
"Wednesday" | "wednesday") echo "What task do you want to add for ${Dayoftask}?"
;;
"Thursday" | "thursday") echo "What task do you want to add for ${Dayoftask}?"
;;
"Friday" | "friday") echo "What task do you want to add for ${Dayoftask}?"
;;
"Saturday" | "saturday") echo "What task do you want to add for ${Dayoftask}?"
;;
"Sunday" | "sunday") echo "What task do you want to add for ${Dayoftask}?"
;;
*) echo "You did not type any day of the week"
;;
	esac
fi

With that code, the errors bash pops out are the following:
line 47: unexpected EOF while looking for matching `"'
line 51: syntax error: unexpected end of file

Any idea of why is this happening? Thanks!

Hmm... Are you using an editor that supports syntax highlighting?

This error:
unexpected EOF while looking for matching `"'

...means that there's something left open somewhere. That could mean that there's an extra quotation mark somewhere, or a missing one. In THIS case, you've left a set of brackets open:

echo "${Tasksarray[${Tasksarraylength}]"
       ^Open bracket                   ^Missing bracket

Problem solved again! Thank you very much. Now, if I'm not being annoying, would you mind telling me how to make a variable, remember? i.e ( I want a a variable, so that every time I open the script, data is kept in that variable, so when I wanna look it, it has data from last time I used the script ). Don't know If I made myself clear, hope I did. Help would be greatly appreciated! Thanks!

Glad to hear that it helped!

For something like that (keeping a variable consistent between runs of the script), you might want to use a temporary file, and ask at the beginning of the script if the user wants to use information from the previous session.

This article has been dead for over six months. Start a new discussion instead.