1.1 ~/sandbox/hello.sh:
#!/bin/bash
echo "Hello, DevOps"chmod +x ~/sandbox/hello.sh
./hello.sh1.2 ~/sandbox/count.sh:
#!/bin/bash
count=3
echo "Count is $count"2.1 ~/sandbox/greet.sh - $1 is the first parameter:
#!/bin/bash
echo "Hello, $1"2.2 ~/sandbox/add.sh - $(( )) performs arithmetic:
#!/bin/bash
echo $(( $1 + $2 ))3.1 ~/sandbox/rect.sh:
#!/bin/bash
length=$1
width=$2
area=$(( length * width ))
perimeter=$(( 2 * (length + width) ))
echo "Area: $area"
echo "Perimeter: $perimeter"- The shebang (
#!/bin/bash) tells the system which interpreter to run the file with;chmod +xmarks it runnable so./hello.shworks (otherwise you'd have to callbash hello.sh). $1is the first argument,$2the second, … and$@is all of them.$(( ))evaluates its contents as arithmetic, so3 + 4becomes7. In a plain string the characters are just text.