Read This! | Picolisp | Picolisp Machine | Pil Sources | Pil Tutorials | Linux | BASH | C-Programmming | Javascipt | Python | Scheme | Operating Systems | AssemblyLanguage | Computer Security | Firewalls | Exploitation | Social Engineering | Metasploit | Emacs | vim | Pharo Smalltalk | Databases | Networking | Machine Learning | Git | Machine Learning | Algorithms | Open Data Science | Vikid's Bash Cookbook |
Bash - if statements
if [ condition ]; then # you can use [[ ]] also your code fi
if [[ "${UID}" -eq 0 ]] then echo 'You are root' else echo 'You are not root' fi
#!/bin/bash if [ $(whoami) = 'root' ]; then echo "You are root" fiIn one line:
if [ $(whoami) = 'root' ]; then echo "root"; else echo "not root"; fi
#!/bin/bash if [ $(whoami) = 'root' ]; then echo "You are root" else echo "You are not root" fi
#!/bin/bash AGE=$1 if [ $AGE -lt 13 ]; then echo "You are a kid." elif [ $AGE -lt 20 ]; then echo "You are a teenager." elif [ $AGE -lt 65 ]; then echo "You are an adult." else echo "You are an elder." fi
#!/bin/bash echo Script name: $0 echo $# arguments if [$# -ne 1]; then echo "illegal number of parameters" fi
$a -lt $b $a < $b $a -gt $b $a > $b $a -le $b $a <= $b $a -ge $b $a >= $b $a -eq $b $a is equal to $b $a -ne $b $a is not equal to $b -e $FILE $FILE exists -d $FILE $FILE exists and is a directory. -f $FILE $FILE exists and is a regular file. -L $FILE $FILE exists and is a soft link. $STRING1 = $STRING2 $STRING1 is equal to $STRING2 $STRING1 != $STRING2 $STRING1 is not equal to $STRING2 -z $STRING1 $STRING1 is empty
22may23 | admin |