for professionalsolution
Linux assignment 2/Assignment 2.docx
· Assignment 2
See Assignment / Project Requirements and Guidelines
Write a shell script to concatenate lists together, and output the resulting list. Do not include any argument that is a sub-list of the entire list. (The script will clean the list of any redundant items.) You must preserve the original order of the list. Remember to account for the following situations:
· a : at the beginning of the list is the same as a . at the beginning of the "list" (:/bin is the same a .:/bin)
· a :: any where in the list is the same as :.: (/bin::/etc is the same as (/bin:.:/etc)
· a : at the end of the list is the same a :. ( /bin: is the same as /bin:. )
· Project usings temporary files will not be graded.
· The input to the script will be color or space separated lists and the output will be a colon separated list with the orignal order preserved and all redunant items removed. USAGE: clean_list list .... Where list a a colon or whitespace separated list. Examples:
prompt> clean_list a a:b a:b:c :x: y:z a:b:c:.:x:y:z prompt>clean_list /bin:/usr/bin:/usr/openwin/bin /usr/bin:/usr/etc:/etc: /usr/bin/X11 .:/bin /bin:/usr/bin:/usr/openwin/bin:/usr/etc:/etc:.:/usr/bin/X11 prompt>clean_list apple:orange:apple pear orange peach apple:orange:pear:peach
REMEMBER TO HANDLE THE SPECIAL CASES OF LEADING :, A ::, AND A TRAILING :
|
|
|
· Example Script very similar to Project 2
The following script is very similar to project 2; however, the major differences are is that it works with a single variable, not the command line arguments and the script tests to see if directories exist (not needed for project 2). Also, for project 2, each positional parameter, can be a special case, where : at the begining of a paramter is really .:, a :: in a parameter is really :.:, and a : at the end of a parameter is :.
You should run this script and see what happens and then modify it to meet the requirements for project 2
That is the tricky part, becase A:B :C --> is A:B:.:C but the code below won't handle that case.
#!/bin/sh
NP=
for P in `echo $PATH | sed -e 's/^:/.:/' -e 's/::/:.:/' -e 's/:$/:./' -e 's/:/ /g'`
do
case $NP in
"")
if [ -d "$P" ]
then
NP="$P"
fi
;;
$P|$P:*|*:$P:*|*:$P)
continue
;;
*)
if [ -d "$P" ]
then
NP="$NP:$P"
fi
;;
esac
done
echo $NP
Linux assignment 2/output for assignment 2.pdf
10/23/2017 https://uml.umassonline.net/bbcswebdav/pid916183dtcontentrid4615042_1/courses/INFO.3120.061.FA17/mar2.sh.res.txt
https://uml.umassonline.net/bbcswebdav/pid916183dtcontentrid4615042_1/courses/INFO.3120.061.FA17/mar2.sh.res.txt 1/4
RAN ==> mar2.sh :
RESULT ==> PASSED
EXPECTED RESULT ==> .
PROGRAM OUTPUT ==> .
RAN ==> mar2.sh : .
RESULT ==> PASSED
EXPECTED RESULT ==> .
PROGRAM OUTPUT ==> .
RAN ==> mar2.sh apple orange pear peach
RESULT ==> PASSED
EXPECTED RESULT ==> apple:orange:pear:peach
PROGRAM OUTPUT ==> apple:orange:pear:peach
RAN ==> mar2.sh x xxx xxx xxxx xxxxx x:xx:xxx:xxxx:xxxxx yx:yxx:yxxx:yxxxx:yxxxxx
RESULT ==> PASSED
EXPECTED RESULT ==> x:xxx:xxxx:xxxxx:xx:yx:yxx:yxxx:yxxxx:yxxxxx
PROGRAM OUTPUT ==> x:xxx:xxxx:xxxxx:xx:yx:yxx:yxxx:yxxxx:yxxxxx
RAN ==> mar2.sh :a b c
RESULT ==> PASSED
EXPECTED RESULT ==> .:a:b:c
PROGRAM OUTPUT ==> .:a:b:c
RAN ==> mar2.sh a :b c
RESULT ==> PASSED
EXPECTED RESULT ==> a:.:b:c
PROGRAM OUTPUT ==> a:.:b:c
RAN ==> mar2.sh a b: c
RESULT ==> PASSED
10/23/2017 https://uml.umassonline.net/bbcswebdav/pid916183dtcontentrid4615042_1/courses/INFO.3120.061.FA17/mar2.sh.res.txt
https://uml.umassonline.net/bbcswebdav/pid916183dtcontentrid4615042_1/courses/INFO.3120.061.FA17/mar2.sh.res.txt 2/4
EXPECTED RESULT ==> a:b:.:c
PROGRAM OUTPUT ==> a:b:.:c
RAN ==> mar2.sh a b::c
RESULT ==> PASSED
EXPECTED RESULT ==> a:b:.:c
PROGRAM OUTPUT ==> a:b:.:c
RAN ==> mar2.sh a b c:
RESULT ==> PASSED
EXPECTED RESULT ==> a:b:c:.
PROGRAM OUTPUT ==> a:b:c:.
RAN ==> mar2.sh :a b c a b c . :a b c a b
RESULT ==> PASSED
EXPECTED RESULT ==> .:a:b:c
PROGRAM OUTPUT ==> .:a:b:c
RAN ==> mar2.sh aa bb: c a b c
RESULT ==> PASSED
EXPECTED RESULT ==> aa:bb:.:c:a:b
PROGRAM OUTPUT ==> aa:bb:.:c:a:b
RAN ==> mar2.sh a b::c:d a b c . :a b c a b
RESULT ==> PASSED
EXPECTED RESULT ==> a:b:.:c:d
PROGRAM OUTPUT ==> a:b:.:c:d
RAN ==> mar2.sh a b c: a b c . :a b c a b
RESULT ==> PASSED
EXPECTED RESULT ==> a:b:c:.
PROGRAM OUTPUT ==> a:b:c:.
10/23/2017 https://uml.umassonline.net/bbcswebdav/pid916183dtcontentrid4615042_1/courses/INFO.3120.061.FA17/mar2.sh.res.txt
https://uml.umassonline.net/bbcswebdav/pid916183dtcontentrid4615042_1/courses/INFO.3120.061.FA17/mar2.sh.res.txt 3/4
RAN ==> mar2.sh /usr/bin /bin
RESULT ==> PASSED
EXPECTED RESULT ==> /usr/bin:/bin
PROGRAM OUTPUT ==> /usr/bin:/bin
RAN ==> mar2.sh /opt/SUNWspro/bin:/usr/bin:/usr/dt/bin:/usr/openwin/bin:/usr/local/bin:/opt/sfw/bin:/usr/sfw/bin:.:/u sr/ccs/bin:/usr/ucb:/usr/platform/SUNW,Sun‐Fire‐ V240/sbin:/sbin:/usr/sbin:/usr/local/sbin:/usr/sadm/bin:/usr/lib:/usr/platform/sun4u/sbin /opt/SUNWspro/bin:/usr/bin:/usr/dt/bin:/usr/openwin/bin:/usr/local/bin:/opt/sfw/bin:/usr/sfw/bin:.:/u sr/ccs/bin:/usr/ucb:/usr/platform/SUNW,Sun‐Fire‐ V240/sbin:/sbin:/usr/sbin:/usr/local/sbin:/usr/sadm/bin:/usr/lib:/usr/platform/sun4u/sbin
RESULT ==> PASSED
EXPECTED RESULT ==> /opt/SUNWspro/bin:/usr/bin:/usr/dt/bin:/usr/openwin/bin:/usr/local/bin:/opt/sfw/bin:/usr/sfw/bin:.:/u sr/ccs/bin:/usr/ucb:/usr/platform/SUNW,Sun‐Fire‐ V240/sbin:/sbin:/usr/sbin:/usr/local/sbin:/usr/sadm/bin:/usr/lib:/usr/platform/sun4u/sbin
PROGRAM OUTPUT ==> /opt/SUNWspro/bin:/usr/bin:/usr/dt/bin:/usr/openwin/bin:/usr/local/bin:/opt/sfw/bin:/usr/sfw/bin:.:/u sr/ccs/bin:/usr/ucb:/usr/platform/SUNW,Sun‐Fire‐ V240/sbin:/sbin:/usr/sbin:/usr/local/sbin:/usr/sadm/bin:/usr/lib:/usr/platform/sun4u/sbin
RAN ==> mar2.sh mar mary mar mark mary martin
RESULT ==> PASSED
EXPECTED RESULT ==> mar:mary:mark:martin
PROGRAM OUTPUT ==> mar:mary:mark:martin
RAN ==> mar2.sh :mar mary mar mark mary martin /usr/bin:/bin:/usr/local/bin:.
RESULT ==> PASSED
EXPECTED RESULT ==> .:mar:mary:mark:martin:/usr/bin:/bin:/usr/local/bin
PROGRAM OUTPUT ==> .:mar:mary:mark:martin:/usr/bin:/bin:/usr/local/bin
RAN ==> mar2.sh martin mar mary mar mark mary martin:
RESULT ==> PASSED
EXPECTED RESULT ==> martin:mar:mary:mark:.
PROGRAM OUTPUT ==> martin:mar:mary:mark:.
RAN ==> mar2.sh x yx yxx . yx xx yxxx xxxx yxxxxx: x:xx:xxx:xxxx:xxxxx yx:yxx:yxxx:yxxxx:yxxxxx
10/23/2017 https://uml.umassonline.net/bbcswebdav/pid916183dtcontentrid4615042_1/courses/INFO.3120.061.FA17/mar2.sh.res.txt
https://uml.umassonline.net/bbcswebdav/pid916183dtcontentrid4615042_1/courses/INFO.3120.061.FA17/mar2.sh.res.txt 4/4
RESULT ==> PASSED
EXPECTED RESULT ==> x:yx:yxx:.:xx:yxxx:xxxx:yxxxxx:xxx:xxxxx:yxxxx
PROGRAM OUTPUT ==> x:yx:yxx:.:xx:yxxx:xxxx:yxxxxx:xxx:xxxxx:yxxxx
RAN ==> mar2.sh . yx xx yxxx xxxx yxxxxx: x:xx:xxx:xxxx:xxxxx yx:yxx:yxxx:yxxxx:yxxxxx
RESULT ==> PASSED
EXPECTED RESULT ==> .:yx:xx:yxxx:xxxx:yxxxxx:x:xxx:xxxxx:yxx:yxxxx
PROGRAM OUTPUT ==> .:yx:xx:yxxx:xxxx:yxxxxx:x:xxx:xxxxx:yxx:yxxxx
RAN ==> mar2.sh yx xx yxxx xxxx yxxxxx x:xx:xxx:xxxx:xxxxx yx:yxx:yxxx:yxxxx:yxxxxx .
RESULT ==> PASSED
EXPECTED RESULT ==> yx:xx:yxxx:xxxx:yxxxxx:x:xxx:xxxxx:yxx:yxxxx:.
PROGRAM OUTPUT ==> yx:xx:yxxx:xxxx:yxxxxx:x:xxx:xxxxx:yxx:yxxxx:.
PASSED ==> 21 100%
FAILED ==> 0 0%