Solved

Shell Scripts (URGENT Please)

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
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…
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.
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.

733 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