Pathworks Project Create pathworks, a facility for viewing, editing and composin
ID: 3705937 • Letter: P
Question
Pathworks Project
Create pathworks, a facility for viewing, editing and
composing the PATH variable in the BASH environment. The
pathworks program should be menu-driven and permit viewing the
current environment PATH variable and changing it, for example:
=================================================================
M A I N M E N U
======= =======
Mon Mar 26 14:06:42 EDT 2018
1> show current PATH
2> create bash_path and bash_list
3> edit bash_list
4> remove bash_list
5> create bash_PATH from bash_list
6> test new path
7> show files
q> quit
Your choice? -- q
That's all, folks!!
$
=================================================================
For this design, capture the PATH to a file called bash_path
in the current directory. Deconstruct it into a list of directories
in bash_list. Provide an editing capability for the bash_list file.
Reconstruct the bash_path file from bash-list after editing. Insert
the new path in a .bash_PATH script for sourcing from your home
directory
Definitions:
PATH -- a variable in the BASH environment containing a string
composed of directory names separated by colons
Files:
bash_path -- a file copy of PATH, gets recreated by mkpath
bash_list -- a file containing the directories
from the PATH but in list form with no colons
bash_path -- a temporary workfile containing a
constructed PATH string
bash_PATH -- a script containing a PATH= assignment
statement suitable for source-ing in
.bash_profile, constructed from bash_path
Example programs include the following:
buildp -- creates bash_list from PATH if needed and
constructs bash_path from it
edlist -- opens the bash_list file in vi
mkpath -- constructs bash_PATH containing a PATH= string
from bash_path
pathworks -- menu script to call all the utilities
showfiles -- shows contents of bash_list, bash_path and bash_PATH
Explanation / Answer
ANSWER:
#! /bin/bash
echo "MAIN MENU"
date
echo "1>show current PATH"
echo "2>create bash_path and bash_list"
echo "3>edit bash_list"
echo "4>remove bash_list"
echo "5>create bash_PATH from bash_list"
echo "6>test new path"
echo "7>show files"
echo "q>quit"
echo "Your choice?"
read ans
looping=3
until [ $looping -lt 2 ]; do
case $ans in
1)
echo "Here is the path"
echo $PATH
echo "Your choice?"
read ans
;;
2)
echo "Create bash_path and bash_list"
echo $PATH > bash_path
if [ -f bash_list ]
then
rm bash_list
fi
for x in `echo $PATH | tr ":" " "`; do echo $x >> bash_list; done
echo "Your choice?"
read ans
;;
3)
echo "edit bash_list using vi"
vi bash_list
echo "Your choice?"
read ans
;;
4)
echo "Remove bash_list"
if [ -f bash_list ]
then
rm bash_list
fi
echo "Your choice?"
read ans
;;
5)
echo "Create bash_PATH from bash_list"
cat bash_list > bash_path
echo "Your choice?"
read ans
;;
6)
echo "test new Path"
echo $PATH
echo "Your choice?"
read ans
;;
7)
echo "how bash files"
ls bash*
echo "Your choice?"
read ans
;;
q)
echo "That's all, folks!"
let looping=1
;;
esac
done