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
Solved

How to write and run a simple Shell script?

Posted on 2006-07-06
8
1,431 Views
Last Modified: 2013-12-06
Can someone give an example with illustration as to How to write and run a simple Shell script?

Can someone explain how the $ (?) works ?

Thanks.
_Esam
0
Comment
Question by:_Esam
  • 5
  • 2
8 Comments
 
LVL 1

Accepted Solution

by:
shmukler earned 125 total points
ID: 17051182
first line should say what shell it is.

for bash type

#/bin/bash

$ with a number gives you number of your argument. $1 is for first argument in the list. you could do echo $1 to print it

#/bin/bash
echo $1 world!

will print the first argument then world!

make sure the script is executable by running $chmod +x ${youfilename}

now you can try:

./${yourscript} hello

and you should see:
hello world!
0
 

Author Comment

by:_Esam
ID: 17051285
Well .. thax...
I will be using Korn Shell on HP-UX

What is the difference between sh and ksh ???

>make sure the script is executable by running $chmod +x ${youfilename}
Could you please explain how I do that?

Thax
_Esam
0
 

Author Comment

by:_Esam
ID: 17051358
When I try this: > make sure the script is executable by running $chmod +x ${youfilename}

It complaints that parameter not set :

This is what I have in the script:

#!/bin/ksh
echo $1 world



And I saved it as hello

Thax
_Esam.
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:_Esam
ID: 17052608
Come on !!
What's wrong here at EE ???

Ppl are so ....?

_Esam
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17052758
> What is the difference between sh and ksh ???
man sh
man ksh

from your shell promt do:

echo '#!/bin/ksh' >hello
echo 'echo $1 world' >>hello
chmod +x hello
./hello heureca

0
 

Author Comment

by:_Esam
ID: 17052874
Sometimes  there are some assumptions the Experts are giving away all the solutions for kids' homework :)
So, they don't quite answer the questions ...........

Why not I man allthecommands and find out by myself all the shell stuffs :) DUH

I am real ..............sad to see this kinda .........

_Esam...
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17052934
> Why not I man ..

.. why do we not post the answer to the question about the difference? 'cause its realy tooooooo much to fit in this forum, you can by countless books which explain in detail what the difference is, or simply STFW and you find even more texts than written in books. Which one should be posted her?
Or we (in particular me) could give a (sarcastic) simple answer to a simple question:
 Q: What is the difference between sh and ksh ???
 A: k

Anyway, you initial question have been answerd, haven't it?
0
 

Author Comment

by:_Esam
ID: 17052986
>Q: What is the difference between sh and ksh ???
 A: k

KOOOOOOOOOOOL
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AIX 5.3 group password policy changes 7 29
how to check for shares on aix 1 85
What are recommended OS for exim mail server? 10 113
Martian Packets Unix 5 67
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
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 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.

856 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