My first attempt at a shell script
My VMware will not run today so I can't try running anything. Can someone look at this and tell me what I need to work on please? I am just looking for someone to point me in the right direction.
Instructions: Write the following shell script called Exercise8 and insert it below: Write a shell script using a bash shell that creates the following directories and • Homework directory on the Knoppix home directory • First directory under Homework directory • Second directory under Homework directory Copies the following files to the directories indicated: • Proposal.txt on the floppy at /media/fd0 to Homework directory • Readme.txt on the floppy at /media/fd0 to First directory in the Homework directory First attempt: #!/bin/bash # mkdir /home/user/$Homework # mkdir –p /home/user/Homework/First # mkdir –p /home/user/Homework/Second # cd /mnt/floppy # cp /media/Proposal.txt /home/user/Homework # cp /media/Readmel.txt /home/user/Homework/First # sync # cd / # umount /mnt/floppy #exit 0 |
Quote:
|
The first three lines after the shebang can be compressed to one
Code:
mkdir -p /home/user/Homework/{First,Second} Code:
cd /mnt/floppy Also keep in mind that the umount-command normally only works for the root-user. |
I have Knoppix, it has been running for a few weeks and now today it says the software isn't installed. The ISO CD is still in my DVD drive. The only thing I did was reboot my laptop. VMware is what I have been using to run Knoppix because I don't have enough hard drive room to install it.
|
Code:
#!/bin/bash Why do you start each line with a #? Do you know its function in BASH? There's a way of writing all 'mkdir' commands in one. Unless specifically instructed you don't need to cd to a directory from where you want to copy stuff. Code:
# cd /mnt/floppy Why did you write the above? I mean it doesn't seem to be in your task instructions. |
Quote:
You don't usually install Knoppix. It funcions as a Live CD, which means that you boot your computer from the Knoppix CD/DVD and it loads to ram memory so your current installation on the hard drive stays intact. |
So I want something more like this?
#!/bin/bash mkdir -p /home/user/Homework/{First,Second} cd /mnt/floppy cp /media/Proposal.txt /home/user/Homework cp /media/Readmel.txt /home/user/Homework/First exit 0 |
Again, place your code in code tags (Go Advanced)
Why do you cd /mnt/floppy? |
Haven't seen that in your first attempt: The instructions state the the floppy is mounted at /media/fd0, so you have to copy your files from /media/fd0/ instead of /media/.
|
I'm still trying to work on the code tags. There is NOTHING in my handouts about them so I am scouring the web.
Latest version #!/bin/bash mkdir -p /home/user/Homework/{First,Second} cp /media/fd0/Proposal.txt /home/user/Homework cp /media/fd0/Readmel.txt /home/user/Homework/First exit 0 |
Quote:
|
Quote:
With Code tags: Code:
(defun numbersp (lst) Without code tags: (defun numbersp (lst) (cond ((null lst) T) ((numberp (car lst)) (numbersp (cdr lst))))) |
Quote:
|
All times are GMT -5. The time now is 12:59 AM. |