%%script bash

# Dependency Variables, set to match your project directories

cat <<EOF > /tmp/variables.sh
export project_dir=$HOME/vscode  # change vscode to different name to test git clone
export project=\$project_dir/bloggy  # change teacher to name of project from git clone
export project_repo="https://github.com/tanayp327/bloggy.git"  # change to project of choice
EOF
%%script bash

# Extract saved variables
source /tmp/variables.sh

# Output shown title and value variables
echo "Project dir: $project_dir"
echo "Project: $project"
echo "Repo: $project_repo"
Project dir: /Users/pankajpatel/vscode
Project: /Users/pankajpatel/vscode/bloggy
Repo: https://github.com/tanayp327/bloggy.git
%%script bash

# Extract saved variables
source /tmp/variables.sh

echo "Using conditional statement to create a project directory and project"

cd ~    # start in home directory

# Conditional block to make a project directory
if [ ! -d $project_dir ]
then 
    echo "Directory $project_dir does not exists... makinng directory $project_dir"
    mkdir -p $project_dir
fi
echo "Directory $project_dir exists." 

# Conditional block to git clone a project from project_repo
if [ ! -d $project ]
then
    echo "Directory $project does not exists... cloning $project_repo"
    cd $project_dir
    git clone $project_repo
    cd ~
fi
echo "Directory $project exists."
Using conditional statement to create a project directory and project
Directory /Users/pankajpatel/vscode exists.
Directory /Users/pankajpatel/vscode/bloggy exists.
%%script bash

# Extract saved variables
source /tmp/variables.sh

echo "Navigate to project, then navigate to area wwhere files were cloned"
cd $project
pwd

echo ""
echo "list top level or root of files with project pulled from github"
ls
Navigate to project, then navigate to area wwhere files were cloned
/Users/pankajpatel/vscode/bloggy

list top level or root of files with project pulled from github
Gemfile
Gemfile.lock
LICENSE
Makefile
README.md
_config.yml
_data
_includes
_layouts
_notebooks
_posts
_site
assets
images
index.md
indexBlogs.md
labnotebook.md
scripts
%%script bash

# Extract saved variables
source /tmp/variables.sh

echo "Navigate to project, then navigate to area wwhere files were cloned"
cd $project
pwd

echo ""
echo "list all files in long format"
ls -al   # all files -a (hidden) in -l long listing
Navigate to project, then navigate to area wwhere files were cloned
/Users/pankajpatel/vscode/bloggy

list all files in long format
total 88
drwxr-xr-x  23 pankajpatel  staff   736 Sep  1 09:11 .
drwxr-xr-x  19 pankajpatel  staff   608 Aug 29 11:55 ..
drwxr-xr-x  15 pankajpatel  staff   480 Sep  5 08:37 .git
drwxr-xr-x   3 pankajpatel  staff    96 Aug 24 22:00 .github
-rw-r--r--   1 pankajpatel  staff   104 Aug 24 22:00 .gitignore
-rw-r--r--   1 pankajpatel  staff   122 Aug 24 22:00 Gemfile
-rw-r--r--   1 pankajpatel  staff  7301 Aug 24 22:01 Gemfile.lock
-rw-r--r--   1 pankajpatel  staff  1081 Aug 24 22:00 LICENSE
-rw-r--r--   1 pankajpatel  staff  3116 Aug 24 22:00 Makefile
-rw-r--r--   1 pankajpatel  staff   611 Sep  1 09:24 README.md
-rw-r--r--   1 pankajpatel  staff   412 Aug 31 12:00 _config.yml
drwxr-xr-x   6 pankajpatel  staff   192 Aug 24 22:00 _data
drwxr-xr-x   9 pankajpatel  staff   288 Aug 24 22:00 _includes
drwxr-xr-x   6 pankajpatel  staff   192 Aug 28 11:59 _layouts
drwxr-xr-x   7 pankajpatel  staff   224 Sep  1 12:03 _notebooks
drwxr-xr-x  11 pankajpatel  staff   352 Sep  1 09:14 _posts
drwxr-xr-x  16 pankajpatel  staff   512 Sep  1 11:01 _site
drwxr-xr-x   4 pankajpatel  staff   128 Aug 31 08:58 assets
drwxr-xr-x   8 pankajpatel  staff   256 Aug 31 11:45 images
-rw-r--r--   1 pankajpatel  staff   391 Aug 31 11:47 index.md


-rw-r--r--   1 pankajpatel  staff    53 Aug 24 22:00 indexBlogs.md
-rw-r--r--   1 pankajpatel  staff    91 Aug 31 11:31 labnotebook.md
drwxr-xr-x   5 pankajpatel  staff   160 Aug 24 22:00 scripts
%%script bash

# Extract saved variables
source /tmp/variables.sh

echo "Look for notebooks"
export notebooks=$project/_notebooks  # _notebooks is inside project
cd $notebooks   # this should exist per fastpages
pwd  # present working directory
ls -l  # list notebooks
Look for notebooks
/Users/pankajpatel/vscode/bloggy/_notebooks
total 128
-rw-r--r--  1 pankajpatel  staff  29793 Sep  5 08:40 2023-08-22-Bash.ipynb
-rw-r--r--  1 pankajpatel  staff  11419 Sep  4 20:11 2023-08-22-Console-Games.ipynb
-rw-r--r--  1 pankajpatel  staff   4880 Aug 31 11:52 2023-08-23-Calculator.ipynb
-rw-r--r--  1 pankajpatel  staff  10206 Sep  5 08:37 2023-08-23-java-hello.ipynb
%%script bash

# Extract saved variables
source /tmp/variables.sh

echo "Look for images in notebooks, print working directory, list files"
cd $notebooks/images  # this should exist per fastpages
pwd
ls -l
Look for images in notebooks, print working directory, list files
/Users/pankajpatel/vscode/bloggy/_notebooks


bash: line 6: cd: /images: No such file or directory


total 120
-rw-r--r--  1 pankajpatel  staff  26506 Sep  5 08:40 2023-08-22-Bash.ipynb
-rw-r--r--  1 pankajpatel  staff  11419 Sep  4 20:11 2023-08-22-Console-Games.ipynb
-rw-r--r--  1 pankajpatel  staff   4880 Aug 31 11:52 2023-08-23-Calculator.ipynb
-rw-r--r--  1 pankajpatel  staff  10206 Sep  5 08:37 2023-08-23-java-hello.ipynb
%%script bash

# Extract saved variables
source /tmp/variables.sh

echo "Navigate to project, then navigate to area wwhere files were cloned"

cd $project
echo "show the contents of README.md"
echo ""

cat README.md  # show contents of file, in this case markdown
echo ""
echo "end of README.md"
Navigate to project, then navigate to area wwhere files were cloned
show the contents of README.md

# My CSA Blog

Welcome to my Tanay Patel's CSA blog! This blog is my personal space to document everything I'm learning and doing during my high school computer science class. Whether it's coding projects, lessons, or cool hacks, you'll find it all here.

## Blogging My Computer Science Journey

As a student passionate about computer science, I'll be sharing my experiences, challenges, and achievements on this blog. This is not only a record of my progress but also a resource for fellow students who share the same interests.

### Visit my Website

[tanayp327.github.io/bloggy](tanayp327.github.io/bloggy/)
end of README.md
%%script bash

# This command has no dependencies

echo "Show the shell environment variables, key on left of equal value on right"
echo ""

env
Show the shell environment variables, key on left of equal value on right

VSCODE_CRASH_REPORTER_PROCESS_TYPE=extensionHost
NVM_CD_FLAGS=-q
GEM_HOME=/Users/pankajpatel/gems
TERM=xterm-color
SHELL=/bin/zsh
CLICOLOR=1
TMPDIR=/var/folders/yq/rjlyd8gs1fs_00jfmk7y31080000gn/T/
CONDA_SHLVL=1
PYTHONUNBUFFERED=1
CONDA_PROMPT_MODIFIER=(base) 
ORIGINAL_XDG_CURRENT_DESKTOP=undefined
MallocNanoZone=0
PYTHONIOENCODING=utf-8
USER=pankajpatel
NVM_DIR=/Users/pankajpatel/.nvm
COMMAND_MODE=unix2003
CONDA_EXE=/opt/anaconda3/bin/conda
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.KCyy4unAyc/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
PAGER=cat
ELECTRON_RUN_AS_NODE=1


VSCODE_AMD_ENTRYPOINT=vs/workbench/api/node/extensionHostProcess
PATH=/usr/local/bin:/Users/pankajpatel/Library/Python/3.9/bin:/usr/local/opt/ruby/bin:/Users/pankajpatel/gems/bin:/Users/pankajpatel/.rbenv/shims:/opt/anaconda3/bin:/opt/anaconda3/condabin:/Library/Frameworks/Python.framework/Versions/3.9/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/opt/ruby/bin:/Users/pankajpatel/gems/bin:/Users/pankajpatel/.rbenv/shims:/opt/anaconda3/bin:/opt/anaconda3/condabin:/Library/Frameworks/Python.framework/Versions/3.9/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
__CFBundleIdentifier=com.microsoft.VSCode
CONDA_PREFIX=/opt/anaconda3
PWD=/Users/pankajpatel/vscode/bloggy/_notebooks
VSCODE_HANDLES_UNCAUGHT_ERRORS=true
MPLBACKEND=module://matplotlib_inline.backend_inline
XPC_FLAGS=0x0
FORCE_COLOR=1
RBENV_SHELL=zsh
XPC_SERVICE_NAME=0
SHLVL=1
HOME=/Users/pankajpatel
APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL=1
VSCODE_NLS_CONFIG={"locale":"en-us","osLocale":"en-us","availableLanguages":{},"_languagePackSupport":true}
PYDEVD_IPYTHON_COMPATIBLE_DEBUGGING=1
LOGNAME=pankajpatel
CONDA_PYTHON_EXE=/opt/anaconda3/bin/python
LC_CTYPE=UTF-8
VSCODE_IPC_HOOK=/Users/pankajpatel/Library/Application Support/Code/1.81-main.sock
VSCODE_CODE_CACHE_PATH=/Users/pankajpatel/Library/Application Support/Code/CachedData/6c3e3dba23e8fadc360aed75ce363ba185c49794
CLICOLOR_FORCE=1
CONDA_DEFAULT_ENV=base
VSCODE_PID=8638
GIT_PAGER=cat
VSCODE_L10N_BUNDLE_LOCATION=
VSCODE_CWD=/
_=/usr/bin/env
%%script bash

# Extract saved variables
source /tmp/variables.sh

cd $project

echo ""
echo "show the secrets of .git"
cd .git
ls -l

echo ""
echo "look at config file"
cat config
show the secrets of .git
total 72
-rw-r--r--    1 pankajpatel  staff    22 Sep  5 08:37 COMMIT_EDITMSG
-rw-r--r--    1 pankajpatel  staff    95 Sep  5 08:37 FETCH_HEAD
-rw-r--r--    1 pankajpatel  staff    21 Aug 24 22:00 HEAD


-rw-r--r--    1 pankajpatel  staff    41 Sep  5 08:37 ORIG_HEAD
-rw-r--r--    1 pankajpatel  staff   305 Aug 24 22:00 config
-rw-r--r--    1 pankajpatel  staff    73 Aug 24 22:00 description
drwxr-xr-x   15 pankajpatel  staff   480 Aug 24 22:00 hooks
-rw-r--r--    1 pankajpatel  staff  5355 Sep  5 08:37 index
drwxr-xr-x    3 pankajpatel  staff    96 Aug 24 22:00 info
drwxr-xr-x    4 pankajpatel  staff   128 Aug 24 22:00 logs
drwxr-xr-x  104 pankajpatel  staff  3328 Sep  5 08:37 objects
-rw-r--r--    1 pankajpatel  staff   112 Aug 24 22:00 packed-refs
drwxr-xr-x    5 pankajpatel  staff   160 Aug 24 22:00 refs

look at config file
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = true
[remote "origin"]
	url = https://github.com/tanayp327/bloggy.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
	remote = origin
	merge = refs/heads/main
%%script bash

# This example has error in VSCode, it run best on Jupyter
cd /tmp

file="sample.md"
if [ -f "$file" ]; then
    rm $file
fi

tee -a $file >/dev/null <<EOF
# Show Generated Markdown
This introductory paragraph and this line and the title above are generated using tee with the standard input (<<) redirection operator.
- This bulleted element is still part of the tee body.
EOF

echo "- This bulleted element and lines below are generated using echo with standard output (>>) redirection operator." >> $file
echo "- The list definition, as is, is using space to seperate lines.  Thus the use of commas and hyphens in output." >> $file
actions=("ls,list-directory" "cd,change-directory" "pwd,present-working-directory" "if-then-fi,test-condition" "env,bash-environment-variables" "cat,view-file-contents" "tee,write-to-output" "echo,display-content-of-string" "echo_text_>\$file,write-content-to-file" "echo_text_>>\$file,append-content-to-file")
for action in ${actions[@]}; do  # for loop is very similar to other language, though [@], semi-colon, do are new
  action=${action//-/ }  # convert dash to space
  action=${action//,/: } # convert comma to colon
  action=${action//_text_/ \"sample text\" } # convert _text_ to sample text, note escape character \ to avoid "" having meaning
  echo "    - ${action//-/ }" >> $file  # echo is redirected to file with >>
done

echo ""
echo "File listing and status"
ls -l $file # list file
wc $file   # show words
mdless $file  # this requires installation, but renders markown from terminal

rm $file  # clean up termporary file
File listing and status
-rw-r--r--  1 pankajpatel  wheel  809 Sep  5 08:41 sample.md
      15     132     809 sample.md


bash: line 30: mdless: command not found

Frequent Linux Commands

  1. ls: List files and directories in the current directory.

  2. pwd: Print the working directory, showing the current directory’s path.

  3. cd: Change the current directory. Use cd [directory] to navigate to a specific directory.

  4. mkdir: Create a new directory. For example, mkdir my_folder creates a folder named “my_folder.”

  5. rm: Remove files or directories. Use rm [file] to delete a file or rm -r [directory] to delete a directory and its contents.

  6. chmod: Change file permissions. It’s used to modify read, write, and execute permissions on files and directories.

  7. ps: Display information about running processes. Use ps aux to see a list of all processes or ps -ef for a similar output.

  8. top: Display a dynamic, real-time system performance summary. Use it to monitor processes, CPU usage, and memory.

  9. wget: Download files from the internet. For example, wget [URL] will download the file specified by the URL to the current directory.

Verify and Update

To verify tools and review their versions, you can use this:

  1. Tool-Specific Commands:
    • Some tools provide specific commands to check their version. For example, java -version for Java or python --version for Python.

Updating a Git Repository via Command Line

To update a Git repository from the command line, follow these steps:

  1. Fetch Updates from the Remote Repository:
    • Fetch changes from the remote repository without merging them into your current branch:
      git fetch origin
      
  2. Push Changes:
    • If you’ve made local changes and want to push them to the remote repository, use git push.
      git push origin main