1

Problem is that when I execute this script using source overspeed (after giving myself execute permission), it asks me "How fast are you going?" as what I set but after I enter any value it gives an error "Event not found" instead of displaying "You are over speeding!!!".

Here is my script by the way:

#!/bin/csh
# Over speed indicator
#
echo -n "How fast are you going?"
set speed = $<
if (speed > 100) echo "You are over speeding!!!"
Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
Anonymous
  • 287

1 Answers1

2

There are a couple of mistakes in your script. The first line should point to your csh executable, which you've identified in the comments as /usr/bin/csh (rather than /bin/csh). The if line is missing the $ to identify speed as a variable. Here is a corrected script

#!/usr/bin/csh
# Over speed indicator
#
echo -n "How fast are you going?"
set speed = $<
if ($speed > 100) echo "You are over speeding\!\!\!"

Ideally you would then run it as ./overspeed rather than source overspeed so that any variables it sets are retained in its own context rather than polluting your interactive shell.

Better than all of this, stop trying to learn a shell language that's fundamentally broken for scripting, and use one of the sh variants instead (ksh or bash). Here is your script rewritten to use bash:

#!/bin/bash
# Over speed indicator
#
read -p "How fast are you going? " speed
if $(( speed > 100 ))
then
    echo 'You are over speeding!!!'
fi

As before, if the script file is executable you can run it with ./overspeed.

Chris Davies
  • 116,213
  • 16
  • 160
  • 287