Using Bash
Using Bash to go through a repository.
echo "Using conditional statement to create a project directory and project"
# Variable section
export project_dir=$HOME/vscode # change vscode to different name to test git clone
export project=$project_dir/APCSP # change APCSP to name of project from git clone
export project_repo="https://github.com/nighthawkcoders/APCSP.git" # change to project of choice
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 this code, we see that the directory already exist.s
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
echo ""
echo "list again with hidden files pulled from github"
ls -a # hidden files flag, many shell commands have flags
echo ""
echo "list all files in long format"
ls -al # all files and long listing
Pretty cool to see that you can easily list all the files using the ls
command.
echo "Look for posts"
export posts=$project/_posts # _posts inside project
cd $posts # this should exist per fastpages
pwd # present working directory
ls -l # list posts
Looking through all the posts on the AP CSP repository.
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
Looking through the Jupyter notebooks.
echo "Look for images in notebooks, print working directory, list files"
cd $notebooks/images # this should exist per fastpages
pwd
ls -l
Only one image in the notebooks folder.
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"
The cat
command allows the user to read the contents of the file, which is really useful.
echo "Show the shell environment variables, key on left of equal value on right"
echo ""
env
The environment.
cd $project
echo ""
echo "show the secrets of .git"
cd .git
ls -l
echo ""
echo "look at config file"
cat config
Finding the secrets of .git!
Learning about bash was really interesting to see the many things it can show the user. It looks like it can be a very helpful tool.
Hacks
Is there anything we use to verify tools we install? Think about versions.
Using the bash script, we can use --version option for each of the tools to verify which version of the tool is installed. For example, executing the command python --version
in bash will give us the version of python the user has installed. This helps to verify the tool that has been set up, and tells the version, so the user can know if they want to update it. Also, we can use conda list
to check the programs and their versions.
Is there anything we could verify with Anaconda?
Using conda list
, we can verify the programs installed. This is also useful to see what version of the program is installed.
How would you update a repository?
To update a remote repository with changes made to the local repository, we can use git push
to push changes from a local repository to the remote repository. To update a local repository with changes made to the remote repository, we use git pull
to pull the changes from the remote repository to the local repository. Additionally, git add and git commit are used to stage and commit changes.
Really cool would be automating a procedure from installation.
This can be done by writing and running programs using the Shell Script.