write a shell script to print hello world

Let's write a shell script to print hello world.




Hello World Script

hello.sh

Example

#Hello World Shell Script

echo "Hello World"


Output

sh hello.sh

Hello World





write a shell script to take 2 arguments to print hello world

We are going to pass "Hello" and "World" as an argument to the shell script Instead of printing it directly.




Hello World Script

hello.sh

Example

#Hello World Shell Script

echo $1 $2


Output

sh hello.sh Hello World

Hello World


Command Line Arguments - While running the script, we need to pass the arguments after sh filename.sh.

$1 holds the argument 1 ("Hello").

$2 holds the argument 2 ("World").


Useful Resources

To learn more shell script examples, you can visit the link