Solved

Shell Scripts (URGENT Please)

Posted on 2000-03-30
5
278 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machineā€¦
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 how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

760 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

21 Experts available now in Live!

Get 1:1 Help Now