Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Execute Bash Shell Online

#!/bin/sh
echo "Shell   scripting  tutorial"

semver bash

# Hello World Program in Bash Shell

###
# semantic version comparition using semver specification https://semver.org/
# This bash script compares pre-releases alphabetically as well
#
# returns 1 when A greater than B
# returns 0 when A equals B
# returns -1 when A lower than B
#
# Usage
# chmod +x semver.sh
# ./semver.sh 1.0.0 v1.0.0-rc.0
# --> 1
#
# Author Ariel Rodriguez
# License MIT
###
__semver() {
  a=$1; b=$2
  # strip word "v" and extract first subset version (x.y.z from x.y.z-foo.n)
  version_a=$(echo ${a//v/} | awk -F'-' '{print $1}')
  version_b=$(echo ${b//v/} | awk -F'-' '{print $1}')

  if [ "${version_a}" \= "${version_b}" ]
  then
    # check for pre-release
    # extract pre-release (-foo.n from x.y.z-foo.n)
    sv_a=$(echo $a | awk -F'-' '{print $2}')
    sv_b=$(echo $b | awk -F'-' '{print $2}')
    # 0 when A is equal to B
    [ "${sv_a}" \= "${sv_b}" ] && echo 0 && return 0
    # 1 when A is not pre-release or (pre-release A exists and is greater than B's pre-release)
    [ -z "$sv_a" ] || [ "${sv_a}" \> "${sv_b}" ] && [ -n "$sv_b" ] && echo 1 && return 0
    # -1 when A is lower than B
    echo -1 && return 0
  fi
  [ "${version_a}" \> "${version_b}" ] && echo 1 && return 0
  echo -1 && return 0
}

versions=(
  0.0.1-rc.0 v0.0.1-rc.2 -1
  v0.0.1-rc.0 0.0.1-rc.0 0
  v0.0.1 v0.0.1-rc.2 1
  v0.0.1 v0.0.1 0
  v0.1.0-rc.0 0.1.0-rc.1 -1
  0.1.0-rc.1 v0.1.0-rc.1 0
  v0.1.0 v0.1.0-rc.1 1
  v0.1.0-rc.1 v0.1.0 -1
)

_assert_is() {
  echo $1 $2 is expected to be $4 $(if [ $3 == $4 ]; then echo "OK"; else echo FAIL got $3; fi)
}

for (( i=0; i<=$(( ${#versions[@]} -3 )); i+=3 ))
do
  echo compare $(_assert_is ${versions[i]} ${versions[ i + 1]} $(__semver ${versions[i]} ${versions[ i + 1]}) ${versions[i+2]})
done

Linux Shell

# comentario do programador
clear
ls -la
mkdir joao
ls -l

test

# Hello World Program in Bash Shell


myList="a b c d e f g h i k l m n o p q r s t u v w x y z"
doList(){
    for c in $myList
    do
        echo $c" ==>"
    done
}

echo $1
doList

UnixTest

# Hello World Program in Bash Shell

echo "Hello World!"

hello

# Hello World Program in Bash Shell

echo "Hello World!"

Deep

# Hello World Program in Bash Shell

echo "Hello World!"

hello

n1= echo "enter your first number"

Execute Bash Shell Online

# Hello World Program in Bash Shell

echo "Hello World!" > here.txt

more here.txt

My testing

#!/bin/sh
SERVICE='jboss'
 
if ps -elf | grep -v grep | grep $SERVICE > /dev/null
then
    echo "$SERVICE service running, everything is fine"
else
    echo "$SERVICE is not running"
    #echo "$SERVICE is not running!" | mail -s "$SERVICE down" root
fi
echo $(uptime) | sed 's/^.\+up\ \+\([^,]*\).*/\1/g'
ls -ltra /etc/hosts
uptime
instmodsh

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.