Homework

Homework Questions? Ask a Tutor for Answers ASAP

Ask an Expert,
Get an Answer ASAP!

Homework

The student is to modify the script student-example-p3

Customer Question
following the instructions in the...
The student is to modify the script student-example-p3 following the instructions in the script.
The purpose of this script is to change the name of files/directories with spaces in the name to have a dash(-). So if a file/directory were named "A B", the new name would be A-B. The script will work on a directory specified on the command line and replace the spaces in the names for all files/directories underneath that directory.
The options to the script are as follows:
-f the -f says to only rename files
-d the -d says to only rename directories
Both -d and and -f may be specifed.
the name of the directory that you will be processing.
For example:
Given the following
$ ls
C D/ dirs.tar fix-spaces*
And the directory "C D" contained the following structure
./C D
./C D/E F
./C D/E F/G H
./C D/E F/G H/J K
./C D/E F/G H/J K/a b
./C D/E F/G H/a b
./C D/E F/a b
./C D/a b
After the script was run,
fix-space -f -d "C D"
the directory structure would be as follows:
C-D
C-D/E-F
C-D/E-F/G-H
C-D/E-F/G-H/a-b
C-D/E-F/G-H/J----K
C-D/E-F/G-H/J----K/a-b
C-D/E-F/a-b
C-D/a-b
Here is a copy of the script - it is alos as an attachment in both UNIX and Windows format.#!/usr/bin/kshUSAGE="$0 -f directory
$0 -d directory
$0 -d -f directory-f rename files
-d rename directories
"usage ()
{
print -u2 "$USAGE"
exit 1
}pathname ()
{
# function provided for the student
print -- "${1%/*}"
}basename ()
{
# function provided for the student
print -- "${1##*/}"
}find_dirs ()
{
# function provided for the student
find "$1" -depth -type d -name '* *' -print
}find_files ()
{
# function provided for the student
find "$1" -depth -type f -name '* *' -print
}my_rename()
{
# the student must implement this function to my_rename
# $1 to $2
# The following error checking must happen:
# 1. check if the directory where $1 resided is writeable,
# if not then report an error
# 2. check if "$2" exists -if it does report and error and don't
# do the mv command
# 3. check the status of the mv command and report any errors
: # remove this line after the function is coded
}fix_dirs ()
{
# The student must implement this function
# to actually call the my_rename funtion to
# change the name of the directory from having spaces to
# changing all of the spaces to -'s
# if the name were "a b", the new name would be a-b
# if the name were "a b" the new name would be a----b
: # remove this line after the function is coded
}fix_files ()
{
# The student must implement this function
# to actually call the my_rename funtion to
# change the name of the file from having spaces to
# changing all of the spaces to -'s
# if the name were "a b", the new name would be a-b
# if the name were "a b" the new name would be a----b
: # remove this line after the function is coded
}WFILE=
WDIR=
DIR=if [ "$#" -eq 0 ]
then
usage
fiwhile [ $# -gt 0 ]
do
case $1 in
-d)
WDIR=1
;;
-f)
WFILE=1
;;
-*)
usage
;;
*)
if [ -d "$1" ]
then
DIR="$1"
else
print -u2 "$1 does not exist ..."
exit 1
fi
;;
esac
shift
done# The student must implement the following:
# - if the directory was not specified, the script should
# print a message and exit# - if the Directory specified is the current directory, the script
# print a error message and exit# - if the directory specified is . or .. the script should print
# an error message and exit# - if both -f and -d are not specified, the script should print a
# message and exit
#if [ "$WDIR" -a "$WFILE" ]
then
fix_files "$DIR"
fix_dirs "$DIR"
elif [ "$WDIR" ]
then
fix_dirs "$DIR"
elif [ "$WFILE" ]
then
fix_files "$DIR"
fi
Submitted: 1 year ago.Category: Homework
Show More
Show Less
Ask Your Own Homework Question
Answered in 6 hours by:
10/25/2016
Tutor: Ingo U, Software Engineer replied 1 year ago
Ingo U
Ingo U, Software Engineer
Category: Homework
Satisfied Customers: 757
Experience: Over 25 years experience in software development. Expert in Microsoft .Net, C#, C++, VB, SQL
Verified

Hi,

please have a look at the following:

http://dl.dropbox.com/u/7895834/fix-spaces?dl=0

I believe it meets the requirements of the assignment. Let me know if you run into any issues.

Regards,

Ingo U

Ask Your Own Homework Question
Customer reply replied 1 year ago
Could you please provide brief explanation to your coding?
Tutor: Ingo U, Software Engineer replied 1 year ago

OK, will do.

Ask Your Own Homework Question
Tutor: Ingo U, Software Engineer replied 1 year ago

Here's a commented version:

https://dl.dropboxusercontent.com/u/7895834/fix-spaces-with-comments

Ask Your Own Homework Question
Customer reply replied 1 year ago
Thanks for your answer.
I received an error as showing below when I run it:
Syntax error at line 176: `||' unexpected
Please advise
Tutor: Ingo U, Software Engineer replied 1 year ago

Hi,

how are you invoking the script? What OS and command shell are you running under?
I just tried the script in a few simple cases in a cygwin environment and it performed as expected...

Perhaps you could take (and upload) a screen shot of the window where you're trying it out to give me some context.

Ask Your Own Homework Question
Customer reply replied 1 year ago
OS: Sun OS .....5.9 Generic c_12230-61 sun4u sparc SunW Sun-Fire-V240
command shell /bin/bash
I only created Folder C D
and run the command ( filename -f -d "C D")
Tutor: Ingo U, Software Engineer replied 1 year ago

OK, I don't immediately see a problem there...

but I haven't been around Sun OS in quite some time, and it's seems there are some differences in the ksh implementation..

Can you verify that the ksh shell is actually present (i.e. is there are /usr/bin/ksh ?)

Also, you can try this version (same link, new file)

http://dl.dropbox.com/u/7895834/fix-spaces-with-comments?dl=0

Not the change is only on the first line, to force using the traditional version of ksh as suggested here:

https://blogs.oracle.com/OTNGarage/entry/new_shell_in_oracle_solaris

I'm not sure it applies here because you seem to be on Solaris 9, not 11 (SunOS5.9 == Solaris 9) .. but worth a try anyway.

A final note; it is possible that somehow the script itself got corrupted during transfer to you... how did you get it to your machine?
Did you by any chance open it in a browser, select the text and past it into a local file (editor window)? THat can cause problems...

Ask Your Own Homework Question
Tutor: Ingo U, Software Engineer replied 1 year ago

Hi, did you have any luck with my suggestions?

Ask Your Own Homework Question
Customer reply replied 1 year ago
Thank you so much for asking I still have the same problem I use shellcheck.com to see what s wrong in the coding I found that something wrong on:
if [ "$WDIR" -a "$WFILE ]
then
fix_files "$DIR"
fix_dirs "$DIR"
elif [ "$WDIR" ]
then
fix_dirs "$DIR"
elif [ "$WFILE" ]
then
fix_files "$DIR"
fi
I am trying now to find what s wrong
Tutor: Ingo U, Software Engineer replied 1 year ago

Well I'm afraid the issues continue to look like they're due to the differences between Solaris and Linux/GNU, where I originally developed that script. The latest problem stems from the Solaris "find" utility not supporting the "-printf" switch - I found some comments about this here:

http://stackoverflow.com/questions/20377804/find-bad-option-printf-find-path-list-predicate-list-shell-scripting

As it suggests, if the GNU utilities (e.g. find) are installed on your Solaris box (under /opt/sfw perhaps, or /usr/sfw or /usr/local/bin) then we could adjust the script to use them explicitly rather than the Solaris 'find' .

It's hard to tell what other problems may exist, because once the first error in 'find' is encountered, the rest of the errors are most likely just a direct consequence and may just go away if we can use the GNU version of 'find'

I don't have access to a Solaris environment, so I'm afraid I can't rewrite the script using the constraints of the native Solaris tools, which could be even more tedious because your Solaris version is fairly old.

Here's another post related to that topic:

http://unix.stackexchange.com/questions/66415/solaris-default-install-user-tools

Ask Your Own Homework Question
Tutor: Ingo U, Software Engineer replied 1 year ago
This answer is protected
Would you like to ask this question?
If you've already paid for this answer, simply Login.
Ask Ingo U Your Own Question
Ingo U
Ingo U
Ingo U, Software Engineer
Category: Homework
Satisfied Customers: 757
757 Satisfied Customers
Experience: Over 25 years experience in software development. Expert in Microsoft .Net, C#, C++, VB, SQL

Ingo U is online now

A new question is answered every 9 seconds

How JustAnswer works:

  • Ask an ExpertExperts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional AnswerVia email, text message, or notification as you wait on our site. Ask follow up questions if you need to.
  • 100% Satisfaction GuaranteeRate the answer you receive.

JustAnswer in the News:

Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.
Web sites like justanswer.com/legal
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.

What Customers are Saying:

Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help.

Mary C.Freshfield, Liverpool, UK

This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!!

AlexLos Angeles, CA

Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult.

GPHesperia, CA

I couldn't be more satisfied! This is the site I will always come to when I need a second opinion.

JustinKernersville, NC

Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around.

EstherWoodstock, NY

Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know.

RobinElkton, Maryland

He answered my question promptly and gave me accurate, detailed information. If all of your experts are half as good, you have a great thing going here.

DianeDallas, TX

< Previous | Next >

Meet the Experts:

LogicPro

LogicPro

Engineer

5,731 satisfied customers

Expert in Java C++ C C# VB Javascript Design SQL HTML

Manal Elkhoshkhany

Manal Elkhoshkhany

Tutor

4,551 satisfied customers

More than 5000 online tutoring sessions.

Linda_us

Linda_us

Finance, Accounts & Homework Tutor

3,138 satisfied customers

Post Graduate Diploma in Management (MBA)

Chris M.

Chris M.

M.S.W. Social Work

2,636 satisfied customers

Master's Degree, strong math and writing skills, experience in one-on-one tutoring (college English)

F. Naz

F. Naz

Chartered Accountant

2,161 satisfied customers

Experience with chartered accountancy

Bizhelp

Bizhelp

CPA

1,887 satisfied customers

Bachelors Degree and CPA with Accounting work experience

Seanna

Seanna

Tutor

1,781 satisfied customers

3,000+ satisfied customers, all topics, A+ work

< Previous | Next >

Related Homework Questions
I need help writing 2 poems in spanish, The listening
The listening passage for this examination consists of two poems. You'll hear the poems three times. These poems are to be written in Spanish as you hear them spoken on the tape. The listening passage for this examination consists of two poems. You'll hear the poems three times. These poems are to be written in Spanish as you hear them spoken on the tape. http://lessons.pennfoster.com/vid/Listening-Comprehension_Side-A_EQ0850.mp3 … read more
Cher
Cher
JustAnswer Expert & Mentor;Teacher/Tutor
Masters Degree
1,381 satisfied customers
Answer, I am a paid member for service from Just Answer.I am
Dear Just Answer,I am a paid member for service from Just Answer.I am working in Excel. I need assistance in providing me a formula for totaling the number of similar numbers in a column of data (900+… read more
NPVAdvisor
NPVAdvisor
CFP Licensee and Practitioner
Master's Degree
180 satisfied customers
In an industrial setting, a pipe is plugged with fats, oils
In an industrial setting, a pipe is plugged with fats, oils and greases. Can you use steam, inside the pipe, to clear the plug? One coworker says yes, another says no. The reasoning behind the no is t… read more
David L.
David L.
Bachelor\u0027s Degree
6 satisfied customers
For LogicPro only: Design a C++ program in which a class
For LogicPro only: Design a C++ program in which a class should manage the free and allocated space. You should use a dynamic node implementation of link list to implement both lists for this assignme… read more
LogicPro
LogicPro
Engineer
Bachelor of Technology
5,731 satisfied customers
You can apply several different worksheets themes from which
You can apply several different worksheets themes from which tab? A.Insert, B. Home, C.File, or D. Page layout! Its not B What would be a situations in which you could use an excel chart to present yo… read more
GLENN
GLENN
Master of Mathematics
343 satisfied customers
6. How many worksheets display in the Excel window when you
6. How many worksheets display in the Excel window when you create a new blank workbook? A. 3 B. 2 C. 4 D. 1 Student Answer: A Answer: Incorrect Reference: Objective 2.17. What would be a situation in… read more
AnswersByEric
AnswersByEric
Software Developer
Associate Degree
37 satisfied customers
Question 18 of 20: Select the best answer for the question.
Question 18 of 20 : Select the best answer for the question. 18. What size paper should you use for a legal document? A. 3″ × 5″ B. 8½″ × 11″ C. 7¼″ × 10½″ D. 8½″ × 14″… read more
JA Engineer
JA Engineer
Broadcast Engineer
Diploma (Honors)
163 satisfied customers
I need help with Exam Number: 00701400 Lesson Name: General
I need help with Exam Number: 00701400Lesson Name: General Math I, Study Unit 2 Pennfoster test… read more
GLENN
GLENN
Master of Mathematics
343 satisfied customers
Answer all three questions and don't exceed 600 words for
Answer all three questions and don't exceed 600 words for each answer while using at least two references to support your answers for each question adopting APA citation in the text and in the referen… read more
F. Naz
F. Naz
Chartered Accountant
CA Finalist & Completed B.com
2,161 satisfied customers
QUESTION 1 A(n) _________________ policy are codified as
QUESTION 1A(n) _________________ policy are codified as standards and procedures that are used when configuring or maintaining systems.0.10000 points Save AnswerQUESTION 2In systems analysis and desig… read more
F. Naz
F. Naz
Chartered Accountant
CA Finalist & Completed B.com
2,161 satisfied customers
I need all the questions answered inthis pdf! I need all
I need all the questions answered inthis pdf! I need all sixty questions on all 21 pages answered!… read more
Steven, M.Acc.
Steven, M.Acc.
Instructor
Master\u0027s Degree
252 satisfied customers
Exam Number: 584002RR I need all t he questions answered in
Exam Number: 584002RR I need all t he questions answered in excel in this pdf file now! Asap!… read more
The-PC-Guy
The-PC-Guy
Bachelor\u0027s Degree
629 satisfied customers
How do you differentiate between an expression and an
How do you differentiate between an expression and an equation? Provide an example of each, where the two are either related to or similar to each other. … read more
GLENN
GLENN
Master of Mathematics
343 satisfied customers
IT 278 Network Administration 1. Server roles and features
IT 278 Network Administration 1. Server roles and features can be added and updated through both a GUI installation and a Server Core installation. In a short essay, explain how to use Windows PowerSh… read more
David L.
David L.
Bachelor\u0027s Degree
6 satisfied customers
Duane will use an open system LAN because he knows the open
Duane will use an open system LAN because he knows the open system will support varieties of hardware and software components made by different vendors. Steve will use a closed system LAN because he k… read more
Chris M.
Chris M.
M.S.W. Social Work
Master's Degree
2,636 satisfied customers
For LogicPro only. need help with this debugging to input it
For LogicPro only.need help with this debugging to input it into raptor// A high school is holding a recycling competition // This program allows a user to enter a student's // year in school (1 throu… read more
LogicPro
LogicPro
Engineer
Bachelor of Technology
5,731 satisfied customers
I need the answer key to penn american literature, 986174RR
I need the answer key to penn foster american literature, 986174RR 986175RR 986176RR 986177RR 986178RR … read more
GLENN
GLENN
Master of Mathematics
343 satisfied customers
For LogicPro only * Reading data strings from a file *
For LogicPro only* Reading data strings from a file * Convert from int based container to templates or generics based * Accommodate dynamic resizing using this algorithm: 1. Starting with a dynamic si… read more
LogicPro
LogicPro
Engineer
Bachelor of Technology
5,731 satisfied customers
Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.

Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.

Show MoreShow Less

Ask Your Question

x