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

# Name: Jerry Hook
# Serial Number: 25
# Assignment Number: 1
# Due Date: 02/18/19

echo "The function of this script is to:"
echo "1. Display the numbers."
echo "2. Add and multiply 3 numbers."
echo "3. Find all odd and even numbers between 1 and the first argument."
echo "4. Indicate whether the numbers entered are one-digit numbers, two-digit numbers or three-digit numbers."
echo "5. Display all prime numbers between 1 and the second number."
echo

read -p "Enter the first number: " num1
read -p "Enter the second number: " num2
read -p "Enter the third number: " num3
echo

echo "The numbers are $num1 $num2 $num3"
echo

sum=$((num1+num2+num3))

echo "$num1 + $num2 + $num3 = $sum"
echo

prod=$((num1*num2*num3))

echo "$num1 * $num2 * $num3 = $prod"
echo

echo "All odd numbers between 1 and $num1"
echo

for i in {1..num1}
do
    rem=$(($i % 2))
    if [ "$rem" -ne "0" ]; then
            echo -n "$i "
    fi
done
echo

echo "All even numbers between 1 and $num1"
echo

for i in {1..num1}
do
    rem=$(($i % 2))
    if [ "$rem" -eq "0" ]; then
            echo -n "$i "
    fi
done
echo

digits1={#num1}
if [ "digits1" -eq "1" ]; then
    echo "$num1 is a one-digit number"
fi
if [ "digits1" -eq "2" ]; then
    echo "$num1 is a two-digit number"
fi
if [ "digits1" -eq "3" ]; then
    echo "$num1 is a three-digit number"
fi
echo

digits2={#num2}
if [ "digits2" -eq "1" ]; then
    echo "$num2 is a one-digit number"
fi
if [ "digits2" -eq "2" ]; then
    echo "$num2 is a two-digit number"
fi
if [ "digits2" -eq "3" ]; then
    echo "$num2 is a three-digit number"
fi
echo

digits3={#num3}
if [ "digits3" -eq "1" ]; then
    echo "$num3 is a one-digit number"
fi
if [ "digits3" -eq "2" ]; then
    echo "$num3 is a two-digit number"
fi
if [ "digits3" -eq "3" ]; then
    echo "$num3 is a three-digit number"
fi
echo

for i in {1..num2}
do
    flag=0
    for j in {2..num2}
    do
        if[ 'expr $i % $j' -eq 0 ]; then
            flag=1
        fi
    done
        
    if[ flag -eq 0 ]; then
        echo -n "$i "
    fi
done
echo

echo "End of script"
echo
echo "Jerry Hook - 2-18-2019"

exit 0

Bubble_sort.sh

# Sorting the array in Bash 
# using Bubble sort 

# Static input of Array 
arr = (10 8 20 100 12) 

echo "Array in original order"
echo ${arr[*]} 

# Performing Bubble sort 
for ((i = 0; i<5; i++)) 
do
	
	for((j = i; j<5-i-1; j++)) 
	do
	
		if ((${arr[j]} > ${arr[$((j+1))]})) 
		then
			# swap 
			temp = ${arr[$j]} 
			arr[$j] = ${arr[$((j+1))]} 
			arr[$((j+1))] = $temp 
		fi
	done
done

echo "Array in sorted order :"
echo ${arr[*]} 

prime

echo -en "\ec"
echo "Script to find prime number"
echo Enter a number
num=50
flag=0
for((i=2;i<=num/2;i++))
do
    flag=$((flag+1))
done
if [ "$flag" -gt 0 ]
then
    echo "Not prime $flag $i"
else
    echo "prime"
fi

Sed test

sed -n -r -e 's/^.*\/([^/]+\.script).*$/\1/p'

looolz

# Hello World Program in Bash Shell

value1="LOKH"
value2="PIDR!"
paramstr="openstack stack create --parameter \"key1=${value1}\" --parameter \"key2=${value2}\""
echo $paramstr

Execute Bash Shell Online

echo "enter the number"
read n
q=$n
a=0
while [ $q – gt 0 ]
do
r= `expr $q % 10 `

 

q= `expr $q / 10 `
a=`expr $a + $r /* $r /*$r `
done
if [ $a=$n ]
then
echo "the number $n is armstrong number"
else
echo "the number $n is not armstrong number"
fi

eric_stuff

# Hello World Program in Bash Shell
set BUILDCONFIGURATION ="node+postgrass"
echo "here we go!"

if [ -z $BUILDCONFIGURATION == *"node\+postgres"* ] 
then 
    echo true  
else
    echo false 
fi 

Execute Bash Shell Online

# Hello World Program in Bash Shell

echo "Hello World!" 

[BASH] Watch Func

function watch() {
    local varName=$1
    local prefix=$2 # Optionnal
    local var

    eval var=\$$varName

    [[ $# -ge 2 ]] && echo "${prefix} : ${var}" || echo "${varName} : ${var}"
}

function test() {
    local var a;

    a=42

    watch a
    watch a "a currently has the value"
}

test

watch func bash

function watch() {
    local varName=$1
    local var

    eval var=\$$varName

    [[ $# -ge 2 ]] && echo "$2 : ${var}" || echo "${varName} : ${var}"
}

function test() {
    echo "test()"

    local var a;

    a=42

    watch a
    watch a "a currently has the value"

    echo "~test()"
}

test

Previous 1 ... 5 6 7 8 9 10 11 ... 101 Next
Advertisements
Loading...

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