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
.
!!!
in your string are likely being interpreted as history expansion commands: see Event not found in sed call in csh script – steeldriver Jun 19 '16 at 23:31($speed >100)
. – michas Jun 19 '16 at 23:38echo $SHELL
please – Chris Davies Jun 19 '16 at 23:45($speed >100)
then also it is showing error "if: Expression syntax" – Anonymous Jun 19 '16 at 23:46/usr/bin/csh
as an output – Anonymous Jun 19 '16 at 23:51