Mouseover script help?

Bash shell script assignment help

  • scope of the assignment 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 colon or space separated lists and the output will be a single colon separated list with all redundant items removed. usage: clean_list list .... where list is 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 script that I have so far. AS you can see my output doesnt acheive the desired result and I cant understand why. [root@win186821wks unix_class]# sh ass2.sh :/usr/bin:/usr/bin/:/usr/not_dup .:/usr/bin:/usr/bin/ script #!/bin/sh for P in `echo $1 | 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

  • Answer:

    Hi derekwtp, as far as I can see, your script has only three little errors - I'll try to leave it mostly the way you started to make the corrections easier to follow: 1) You are using /bin/sh - that's a common mistake and your script will run with that mistake on most systems... however /bin/bash != /bin/sh !!! 2) Your echo statement only captures the input up to the first white space. 3) You are using -d which is checking if your path points to valid directories... that is not the task you set out to complete - you just wanted to check if a path can be condensed (/usr/not_dup does not exist on your system, so it is crossed off your list). So you actually solved a more complex problem than you were required to solve... just eliminate the if statements and your code runs as required. #!/bin/bash for P in `echo $* | sed -e 's/^:/.:/' -e 's/::/:.:/' -e 's/:$/:./' -e 's/:/ /g'` do case $NP in "") NP="$P" ;; $P|$P:*|*:$P:*|*:$P) continue ;; *) NP="$NP:$P" ;;esac done echo $NP I hope this helps - if I somehow misunderstood the requirements of your task, or if you have further questions, please feel free to request a clarification. voyager-ga

derekwtp-ga at Google Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.