Solved

Shell Scripts (URGENT Please)

Posted on 2000-03-30
5
279 Views
Last Modified: 2010-04-21
I need to run shell scripts on my Unix machine. On the $ prompt, when I type echo $SHELL, it shows /bin/tcsh.
If I type myvariable=hello, it says "command not found". How to run this command.

Also for the following script:

x=0
while [$x -lt 10]
do
echo $x
x = 'echo $x + 1'
done

To run the above do I need to store it in a file and then execute the file? Please let me know in detail. Thanks
0
Comment
Question by:skundu
  • 2
  • 2
5 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 2669841
#!/bin/tcsh
set x=0
while ( $x < 10 )
echo $x
@ x += 1
end
0
 

Author Comment

by:skundu
ID: 2670272
Thanks a lot. It worked.
Please tell me in tcsh shell, how can I assign a variable (say fruit) to a value (say apple)??
$fruit=apple
above command gives me error.

Also I have tchs shell, can I work on any other shell (like bash) somehow.
Please reply soon. Thanks.
0
 
LVL 1

Accepted Solution

by:
Astroman earned 100 total points
ID: 2670542
to work on another shell, you can either invoke that shell, e.g.

> bash

or

> sh

whichl will drop you into that shell, or if you wnat to run a scrip in a different shell (like bash or sh which are better shells for scripting than tcsh), just replace the top line of ozo's script:

#!/bin/tcsh

with

#!/bin/sh

The general form is "#!<path to command interpreter", so you can use this to use different interpreters entirly (such as perl).

Once you are using the bash, or sh shells, with a few changes, your original script should work fine (see below)

---------------------------

#!/bin/sh
x=0
while [ $x -lt 10 ]
do
  echo $x
  x=`expr $x + 1`
done

---------------------------

Hope this helps,

Leon
0
 

Author Comment

by:skundu
ID: 2670737
Thanks.
0
 
LVL 84

Expert Comment

by:ozo
ID: 2671174
in tcsh

set fruit=apple
echo $fruit
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now