Last active
September 16, 2022 16:43
-
-
Save epynic/0743de36a2b322b267fe8b9f4b43bc00 to your computer and use it in GitHub Desktop.
Revisions
-
epynic revised this gist
Jan 31, 2019 . 7 changed files with 102 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ #debugging shellscripts -x would show the scrips line by line and output followed by #!/bin/bash -x TEST_VAR="test" echo "$TEST_VAR" #custom #set -x / start debugginh #set +x / stop #-ex exit on stop #-v prints shell before substitution are applied #-vx #DEBUG="echo" #$DEBUG ls 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ #!/bin/bash #case statement example read -p "Enter y or n:" ANSWER case "$ANSWER" in [yY]|[yY][eE][sS]) echo "You answered yes." ;; [nN]|[nN][oO]) echo "You answered no." ;; *) echo "Invalid answer." ;; esac 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ #!/bin/bash #decisions HOST_NAME="windows" #simple if if [ $HOST_NAME = "ubuntu" ]; then echo "Ubuntu for humans" fi #if else if [ $HOST_NAME = "ubuntu" ]; then echo "Ubuntu for humans" else echo "Windows for !humans" fi #if elif else if [ $HOST_NAME = "ubuntu" ]; then echo "Ubuntu for humans" elif [ $HOST_NAME = "windows" ]; then echo "We !Love Windows" else echo "Windows for !humans" fi 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ #!/bin/bash #file operators FILE="basic.sh" if [ -e $FILE ]; then echo "File Exists" else echo "No File Found" fi #-d,e,r,w,x #string operations #arithmetic operations are allowed #arg1 -eq arg2 - equalto #arg1 -ne arg2 - !equalto #arg1 -lt arg2 - less than #arg1 -le arg2 - less than equalto #arg1 -gt arg2 - greater than #arg1 -ge arg2 - greater than equalto 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ #syslog #logger -p user.info "$MESSAGE" #logger -i -t randomly -p user.info "$MESSAGE" #while loop while [ "$CORRECT" != "y" ] do read -p "Whats your name ? " NAME read -p "Is your Name: $NAME - correct ?" CORRECT done #read file line by line LINE_NUM=1 while read LINE do echo "${LINE_NUM}: ${LINE}" ((LINE_NUM++)) done < /etc/fstab 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ #!/bin/bash #loops COLORS="red green blue" for COLOR in $COLORS do 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ #!/bin/bash #wildcards *.txt match zero or more characters #?.txt match exactly one character ls *\? #file end with ? ls ? #file 1 character ls -l *.txt ls c[aeiou]t #character class #can use this with mv cp rm #copy .html files to another folder - wildcards cd /var/www for FILE in *.html do echo "Copying $FILE" cp $FILE /var/www-backup done -
epynic created this gist
Jan 31, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ #!/bin/bash #declare variable SERVER_NAME="nginx" echo $SERVER_NAME echo "We are running on $SERVER_NAME" echo "We are ${SERVER_NAME}er"; #command output to variable SERVER_NAME=$(hostname) echo "We are running on $SERVER_NAME"