[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1453
  • Last Modified:

How to write and run a simple Shell script?

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
_Esam
Asked:
_Esam
  • 5
  • 2
1 Solution
 
shmuklerCommented:
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
 
_EsamAuthor Commented:
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
 
_EsamAuthor Commented:
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
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
_EsamAuthor Commented:
Come on !!
What's wrong here at EE ???

Ppl are so ....?

_Esam
0
 
ahoffmannCommented:
> 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
 
_EsamAuthor Commented:
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
 
ahoffmannCommented:
> 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
 
_EsamAuthor Commented:
>Q: What is the difference between sh and ksh ???
 A: k

KOOOOOOOOOOOL
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now