Computing.Net > Forums > Unix > Simple Unix script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Simple Unix script

Reply to Message Icon

Name: Garlicbread
Date: May 13, 2008 at 19:44:28 Pacific
OS: Unix
CPU/Ram: P4 2.8 Ghz
Product: Dell
Comment:

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




Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: May 13, 2008 at 21:49:36 Pacific
Reply:

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
clear

echo 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.

0

Response Number 2
Name: Garlicbread
Date: May 14, 2008 at 08:18:13 Pacific
Reply:

Thank you for your help!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Simple Unix script

HELP(short unix scripts) www.computing.net/answers/unix/helpshort-unix-scripts/4246.html

Simple UNIX script or command? www.computing.net/answers/unix/simple-unix-script-or-command/7154.html

Unix Script Error, Quel Strange www.computing.net/answers/unix/unix-script-error-quel-strange/5244.html