Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello, I am new to unix and am trying to write a simple script that will ask for a first name and then use an if statement to output a phrase. Below is the script that I have written. I get a "variable not defined" error. How can I make this work? Thank you.
#!/bin/csh
clear
echo
echo Enter your First Name:
set FirstnName = $<read1
if $read1 = "FirstnName"
then
echo "phrase"
fi

First, the $< redirects standard input. Below, it's used to set the read1 variable. I have no idea what you are doing in your script, but that's why you get an "undefined variable" error.
Second, your if syntax is incorrect. use parenthesis as shown, terminate with endif - not fi, and then has to be on the same line as if:
#!/bin/csh
clearecho Enter your First Name:
set read1 = $<if ( "$read1" == "nails" ) then
echo "phrase"
endif
Finally, if you have an option, I wouldn't use the csh. Use sh, ksh, or bash.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |