problem with a script on Bash

Masasa

New Member
Joined
Apr 2, 2021
Messages
2
Reaction score
0
Credits
31
Hi! I'm new, I only started learning Linux 2 days ago. I have a problem with a script on bash. I can't find and fix the error. Can you help me?
Thx Maria

#!/bin/bash

function Ddate()
{
zenity —info \
—title "Date and Time" \
—text "Today is $(date)"
}

function Dcalendar()
{
zenity —calendar \
—title "Calendar"
}

function DReminder()
{
—title "Reminder" \
—entry-text "Birthday/Events..."
}

function DDelete()
{
zenity —entry-text "Empty trash?" > \
—title "DELETE"
if [ —title "DELETE"]

then
rm -rf ~/.local/share/Trash/info/* ~/.local/share/Trash/files/*
}

function Temperature()
{
zenity —entry-text "CPU Temperature" > \
—title "CPU Temperature"
if [ —title "CPU Temperature"]

then
zenity —info —text=$(vcgencmd measure_temp) —title="CPU Temperature"
}

function Screenshot()
{
zenity —entry-text "Screenshot" > \
—title "Press"
if [ —title "Press"]

then
zenity —info —text=$(scrot -d2) —title="Screenshot"
}

while true;
do
choice="$(zenity —height 275 —width 450 \
--list \
--title="Menu" \
--column="Function" —column="Description" \
Date 'Display the actual date and time.' \
Calendar 'Display an interactive calendar.' \
Delete 'Delete trash.' \
Temperature 'CPU Temperature.' \
Screenshot 'Screenshot.' \
Exit 'To quit this script.')"

case $choice in
Date) Ddate;;
Calendar) Dcalendar;;
Delete) rm -rf ~/.local/share/Trash/info/* ~/.local/share/Trash/files/*;;
Temperature) zenity —info —text=$(vcgencmd measure_temp);;
Screenshot) zenity —info —text=$(scrot -d5);;
Exit) break;;

esac

done
 


Upd.
I'm learning linux on raspberry pi, so this script is important to me, especially the screenshot and temperature functions.

If you copy the text to the terminal, the script works. But after running in the terminal, it doesn't work. I'm confused. o_O
 
All of your ifstatements are missing a fi statement at the end.

e.g.
Bash:
if [ something ]
then
       doSomething
fi
That’s the only obvious error I can see from taking a quick look.

What error messages are you getting when you run the script?

Also, have you tried running your script in debug mode in bash?
e.g.
Bash:
bash -x /path/to/script

Where /path/to/script is the path/filename of the script to run.

Running the script through bash in debug mode it will list each line that is executed and show the results of each line.
That will give you a more precise idea of which line (or lines) your script is failing on!
 
G'day Maria and welcome to linux.org :)

I am moving this Thread to Command Line

https://linux.org/forums/command-line.145/

... where scripting questions are also handled.

@KGIII and @JasKinasis note the change of venue.

Hold on to your hats, we're off on a magic carpet ride with the wizard.

Chris Turner
wizardfromoz
 

Members online


Latest posts

Top