Created
October 11, 2019 02:17
-
-
Save filevich/0f5e30a769513aede63069afae6f06b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# give it executable permission | |
# `chmod +x filename.sh` | |
echo "Total arguments : $#" | |
echo "1st Argument = $1" | |
echo "2nd argument = $2" | |
# accessing parameters by name | |
function greeting() { | |
str="Hello, $name" | |
str+=" nice to meet you.\nwelcome to: THE SHELL TRAINIG SERIES" | |
echo $str | |
} | |
echo -n "Enter Your Name: " | |
read name | |
msg=$(greeting) | |
echo -e $msg | |
# accessing parameters by index | |
sum() { | |
res=$(($1 + $2)) | |
echo "$res" | |
} | |
while [[ true ]]; do | |
echo -n "Ingresa un numero entre [1..10]: " | |
read num | |
# checkeo que es un numero (primero como string; notese los parentesis-rectos) | |
if [[ ! $num =~ ^-?[0-9]+$ ]] ; then | |
echo "No good" | |
exit | |
fi | |
# lo checkeo como integer (notese los parentesis-curvos) | |
# if ((num<1)); then | |
# echo "$num es menor que 1" | |
# elif ((num>10)); then | |
# echo "$num es mas grande que 10" | |
# fi | |
# checkeo 2x1 | |
if ((num<1)) || ((num>10)); then | |
echo "$num no es valido" | |
else | |
break # breakea el while | |
fi | |
done | |
# pequena aritmetica | |
(( num = num + 1 )) | |
echo "its sucessor is $num" | |
total=$(sum num 123) | |
echo "and $num + 123 = $total" | |
echo -n "Enter username: " | |
read username | |
echo -n "Enter password: " | |
read password | |
if [[ ( $username == "admin" && $password == "secret" ) ]]; then | |
echo "valid user" | |
else | |
echo "invalid user" | |
fi | |
echo -n "Enter directory name: " | |
read newdir | |
if [ -d "$newdir" ]; then | |
echo "Directory exist" | |
else | |
`mkdir $newdir` | |
echo "Directory successfully" | |
fi | |
# last echo must not contain `-n` flag!!! | |
# read a file | |
file='book.txt' | |
while read line; do | |
echo $line"asdsss" | |
done < $file | |
# delete a file | |
echo -n "Enter filename to remove: " | |
read fn | |
echo "y or n" | |
rm -rf $fn | |
# date | |
Year=`date +%Y` | |
Month=`date +%m` | |
Day=`date +%d` | |
Hour=`date +%H` | |
Minute=`date +%M` | |
Second=`date +%S` | |
echo `date` | |
echo "Current Date is: $Day-$Month-$Year" | |
echo "Current Time is: $Hour:$Minute:$Second" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment