?
Solved

Shell Scripts (URGENT Please)

Posted on 2000-03-30
5
Medium Priority
?
284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 300 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.
Suggested Courses
Course of the Month8 days, 17 hours left to enroll

764 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