请大家帮忙做一个shell的题

请大家帮忙做一个shell的题

1.Write a shell program called create_file.sh that will accept a variable number of command line arguments. The shell program will create a new file associated with each commandline argument(use the touch command), and shows(use the ls -l command) the contents of the current directory





2.Create a shell program called my_ask.sh that will ask the user if he or she would like to see the contents of the current directory. Inform the user that you are looking for a yes or no answer.Issue an error message if the user does not enter yes or no. If the user enters yes display the contents of the current directory. If the user enters no, ask what directory he

or she would like to see the contents of. Get the user's input and display the contents of that directory. Remember to verify that the requested directory exists prior to displaying its contents.



3.Create a shell program called my_menu.sh that will display a simple menu that has three options.

    a. The first option will run who;

    b. The second option will run pwd;

    c. Quit

   The menu should be redisplayed after each selection is completed, until the user enters 3 .



4.Create a program my_cp.sh which will copy one file to another. The program will accept two command line arguments, a source and a destination. Check for the following

   situations:

    a) It should make sure that the source and destination do not reference the same file.

    b) The program should verify that the destination is a file.

    c) The program should verify that the source file exists.

    d) The program should check to see if the destination exists. If it does, ask the user if he or she wants to overwrite it.


谢谢^^终于找到这个不错的论坛,以后常来和大家交流      
复制内容到剪贴板
代码:
[color=blue]-(guest@mac:tty1)-(work)-
[8563 0] %[/color] ls  
create_files.sh
[color=blue]-(guest@mac:tty1)-(work)-
[8563 0] %[/color] cat create_files.sh
#! /bin/bash

touch "$@"
ls -l
[color=blue]-(guest@mac:tty1)-(work)-
[8563 0] %[/color] ./create_files.sh file1 file2 file3
total 8
-rwxr-xr-x  1 clark  clark  31 19 Jun 18:02 create_files.sh
-rw-r--r--  1 clark  clark   0 19 Jun 18:02 file1
-rw-r--r--  1 clark  clark   0 19 Jun 18:02 file2
-rw-r--r--  1 clark  clark   0 19 Jun 18:02 file3
[color=blue]-(guest@mac:tty1)-(work)-
[8563 0] %[/color]
      
复制内容到剪贴板
代码:
[color=blue]-(guest@mac:tty1)-(work)-
[1269 0] %[/color] cat my_ask.sh
#! /bin/bash

dir=.
echo -n "wud u like to see the content of current dir ? [yes/no] "
read answer
if [ "$answer" = no ]; then
    echo -n "plz input the dir u'd like to see the content of: "
    read dir
elif [ "$answer" != yes ]; then
    echo "error: u must input yes or no"
    exit 1
fi

if [ -d "$dir" ]; then
    echo "--- content of the dir '$dir' ---"
    ls "$dir"
else
    echo "error: dir '$dir' does not exist"
    exit 1
fi
[color=blue]-(guest@mac:tty1)-(work)-
[1269 0] %[/color] ./my_ask.sh
wud u like to see the content of current dir ? [yes/no] yes
--- content of the dir '.' ---
create_files.sh file1           file2           file3           my_ask.sh
[color=blue]-(guest@mac:tty1)-(work)-
[1269 0] %[/color] ./my_ask.sh
wud u like to see the content of current dir ? [yes/no] no
plz input the dir u'd like to see the content of: /usr/local/svn/  
--- content of the dir '/usr/local/svn/' ---
bin     include info    lib     man     share
[color=blue]-(guest@mac:tty1)-(work)-
[1269 0] %[/color] ./my_ask.sh
wud u like to see the content of current dir ? [yes/no] no
plz input the dir u'd like to see the content of: /foo
error: dir '/foo' does not exist
[color=blue]-(guest@mac:tty1)-(work)-
[1269 1] %[/color] ./my_ask.sh
wud u like to see the content of current dir ? [yes/no] xx
error: u must input yes or no
[color=blue]-(guest@mac:tty1)-(work)-
[1269 1] %[/color]
      
3. 略
4. 略