LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Bash script, im still new to linux (https://www.linuxquestions.org/questions/linux-general-1/bash-script-im-still-new-to-linux-4175678045/)

Himeose 07-02-2020 11:06 PM

Bash script, im still new to linux
 
How to append an existing file?
The existing file in the wastebasket will have the version number zero appended to it and the newly deleted file will have version number 1 appended to it.
How the loop looks like?

My script be like

Quote:

#!/bin/sh
read file
mv $file mywastebasket
rm -i /home/himeose/mywastebasket/
So how am i gonna proceed?

actually this is the question given
Instructions


The goal of this assignment is to write a shell script to replace the rm command and
provide undelete capability similar to MS-DOS. Write a shell program to duplicate the
Linux rm command with the following features:

Your new rm command is delete

1. It will have a switch -i that will act in the same manner as in the rm command.

2. Instead of deleting the files, it will move them to a mywastebasket directory. If the file
already exists in the mywastebasket directory, then the existing file (in the
mywastebasket) will have the version number zero appended to it and the newly deleted
file will have version number one appended to it.
If the version number setup is already
in use for that file then the newest one will simply have the next version number in the
series appended to it. It's your choice as to what system to use for this. Just be sure that
it is a unique system and will not be part of any normal file naming convention you might
use.
-----------
For step 2

The loop for append
Mybe i should use
Quote:

If [ conditional expression1 ]
then
statement1
statement2
.
elif [ conditional expression2 ]
then
statement3
statement4
.
.
.
else
statement5
fi
how do i implement the append into the loop?
--------------
3. It will have a switch -c that will clear the entire mywastebasket after asking for
confirmation. The -i and -c switches may be combined to ask for confirmation on
individual files.
-----------------
for the step 3 i should using alias right for substitute -c,
-----------------

Don't forget that wildcards and multiple files are allowed on the command line. The
switches when combined may be in any order but must be before any filenames. Your
program must also catch any operator errors.

I'm still learning by myself and has poor understanding of linux things.

berndbausch 07-03-2020 01:04 AM

Bash script, im still new to linux
 
Please make your code more readable with code tags (see my signature).

Quote:

Originally Posted by Himeose (Post 6140800)
How to append an existing file?

You want to append an existing file to what?
Quote:

rm -i /home/himeose/mywastebasket/
the above command will fail. To remove an empty directory, use rmdir. To remove a directory including all contents, rm -r.

In the remaining text, I don't know what is code, what is pseudocode, what is command output and what are your comments, In other words, I don't understand what you mean.

Can you provide an example?

shruggy 07-03-2020 03:52 AM

Just curious, where is the top post you're answering to?

Himeose 07-03-2020 03:59 AM

Im post it, then edit, but after that it suddenly missing��

crts 07-03-2020 04:24 AM

Quote:

Originally Posted by Himeose (Post 6140860)
Im post it, then edit, but after that it suddenly missing��

This is highly unusual. I started another thread in suggestions&feedback in order to investigate this issue.

berndbausch 07-03-2020 07:16 AM

Quote:

Originally Posted by shruggy (Post 6140859)
Just curious, where is the top post you're answering to?

A glitch?

berndbausch 07-03-2020 07:21 AM

OP has created a new thread https://www.linuxquestions.org/quest...on-4175678054/.

Perhaps best to delete this one. I will report it.


All times are GMT -5. The time now is 06:36 PM.