Last active
August 31, 2022 15:18
-
-
Save PompaDonpa/3d6dba8f25251fcac4353e54a540e8e1 to your computer and use it in GitHub Desktop.
Shell Basics
This file contains 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
foo=bar | |
" The value is '$foo'" # prints The value is bar | |
foo=$(pwd) | |
" We are in '$foo' " # prints We are in < PATH > | |
cat <(ls) <(ls ..) # concats the output of ls and ls .. | |
mkdir sandbox / # Will need permissions | |
sudo !! # !! inserts mkdir sandbox / | |
ls & # runs in the background | |
; # executes the next command | |
true || echo "Hello World" # will always print "Hello World" | |
true && echo "Hello" # will always print "Hello" | |
false && echo "World" # will never print "World" | |
$_ # returns the last argument | |
$? # returns if last command was successful | |
$0 # the current command running | |
$# # the number of arguments | |
$$ # the process id | |
$@ # all the arguments | |
echo "Starting program at $(date) " | |
echo "Running program $0 with $# arguments with pid $$" | |
for file in "$@"; do | |
grep foobar "$file" > /dev/null 2> dev/null | |
# When pattern is not found, grep has exit status 1 | |
# We redirect STDOUT and STDERR to a null register since we do not care | |
if [[ "$?" -ne 0 ]]; then | |
echo "File $file does not have any foobar, adding one" | |
echo "# foobar" >> "$file" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment