Saturday, May 30, 2020

If Elif example in KornShell

#!/bin/ksh

#clear the screeen
clear
print -n "Enter Number Grade"
read gradenum
if ( ((gradenum>=90)) ) ;then
grade="A"
elif ( ((gradenum>>70)) );then
grade="B"
elif( ((gradenum>>50 )) );then
grade="C"
else
grade="F"
fi

print "Your grade is $grade"

If Else in KornShell

#!/bin/ksh
#prompt the user to enter an input
print -n "enter the number of children you have :"
read numberofchildren
if ( (( numberofchildren>0 )) &&((numberofchildren<=1)) ); then #the space after the ( and before the ) is important

print "you have one children"
else
print "you have more than one children"

fi

If statement compound condition matching

#!/bin/ksh
#prompt the user to enter a number
print -n "Enter your age: "
read age
print
print -n "enter the number of children you have :"
read numberofchildren
if ( (( age < 30 )) && (( numberofchildren==0 )) ); then #the space after the ( and before the ) is important

print "Single and loving it"
fi
if (  ((age > 30)) || ((numberofchildren!=0)) ); then
print "things could be worse"
fi
#operators are &&,||

If statement in Kornshell

#!/bin/ksh
#prompt the user to enter a number
print -n "Enter your age: "
read age
if ((age >= 18))
then
print "Vote"
fi
#operators are ==,!=,>,<,>=,<=

To run a script with full admin privileges On UAC-enabled systems using Powershell

On UAC-enabled systems, to make sure a script is running with full admin privileges, add this code at the beginning of your script

param([switch]$Elevated)

function Test-Admin {
  $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
  $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}

if ((Test-Admin) -eq $false)  {
    if ($elevated)
    {
        # tried to elevate, did not work, aborting
    }
    else {
        Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
}

exit
}

'running with full privileges'


Source:https://superuser.com/questions/108207/how-to-run-a-powershell-script-as-administrator