My First Shell Script (basic)

Configurare noua (How To)

Situatie

You want to create your first shell script.

Solutie

Pasi de urmat
Example 1. "Hello World"

#!/bin/sh
echo "Hello world"

--- --- --- --- --- ---
Demo :

sorina@sorina-RO ~
$ vi example1.sh

sorina@sorina-RO ~
$ cat example1.sh
#!/bin/sh
echo "Hello world"

sorina@sorina-RO ~
$ sh ./example1.sh
Hello world
--- --- --- --- --- ---
Example 2. Argument

#!/bin/bash

# example of using arguments to a script
echo "My first name is $1"
echo "My second name is $2"
echo "Total number of arguments is $#"

--- --- --- --- --- ---
Demo :

sorina@sorina-RO ~
$ vi example2.sh

sorina@sorina-RO ~
$ cat example2.sh
#!/bin/bash

# example of using arguments to a script
echo "My first name is $1"
echo "My second name is $2"
echo "Total number of arguments is $#"

sorina@sorina-RO ~
$ sh ./example2.sh Andreea Sorina
My first name is Andreea
My second name is Sorina
Total number of arguments is 2
--- --- --- --- --- ---

Tip solutie

Permanent

Voteaza

(25 din 50 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?