Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Shell Scripts (URGENT Please)

Posted on 2000-03-30
5
Medium Priority
?
286 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

Independent Software Vendors: 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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
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…
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…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Suggested Courses

596 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