Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Shell Scripting (2)

  • 15-11-2002 12:16pm
    #1
    Registered Users, Registered Users 2 Posts: 10,148 ✭✭✭✭


    The rm command can be dangerous - you use it to delete files without being prompted. You also do not get any feedback. You are required to write a shell script called del which has the following specification:

    Name: del - delete files interactively.
    Syntax: del <filename>
    Description: This is the outline for del:
    .Select sh
    .Get the filename from the command line ($1)
    .If there is no file with that name print the error message "File does not exist".
    .Otherwise:
    ask if the user wants to delete the file.
    Read the user's choice (y/n)
    If the choice is yes (y) remove the file and print the message "The file has been deleted".
    Otherwise, print the message "The file has not been deleted".

    I can do the first of the 2 instructions but get the rest out! Anyone help me?!


Comments

  • Closed Accounts Posts: 5,564 ✭✭✭Typedef


    The rm command can be dangerous - you use it to delete files without being prompted. You also do not get any feedback.

    in ~/.bashrc

    have this

    alias rm='rm -i'

    Problem solved client happy, wierdos stored in our custom made storage facility.

    man rm
    rtfm


  • Closed Accounts Posts: 1,295 ✭✭✭Meh


    If there is no file with that name print the error message "File does not exist".
    http://www.cyberciti.biz/nixcraft/linux/docs/uniqlinuxfeatures/lsst/ch03sec02.html
    test -f <filename>
    
    will test if a file exists. The link contains some examples of usage.
    Read the user's choice (y/n)
    http://www.cyberciti.biz/nixcraft/linux/docs/uniqlinuxfeatures/lsst/ch02sec10.html tells you how to read keyboard input into a variable. You can then compare this variable to "y" or "n"


  • Registered Users, Registered Users 2 Posts: 10,148 ✭✭✭✭Raskolnikov


    Eeep, i hate shell programming.


  • Closed Accounts Posts: 3,859 ✭✭✭logic1


    Don't post your homework here.

    .logic.


  • Registered Users, Registered Users 2 Posts: 10,148 ✭✭✭✭Raskolnikov


    Originally posted by logic1
    Don't post your homework here.

    .logic.

    I don't see what the big deal is, i wasn't asking for a complete solution or someone to do my 'homeowork', just some help and i got it from Meh. Anyway i don't see why my question should be any different from someone who is learning this of there own accord.

    If you don't want anyone to get help from this forum then just delete any posts from people looking for help.


  • Advertisement
  • Closed Accounts Posts: 3,859 ✭✭✭logic1


    Homework questions are banned. They always have been and always will be. Do the work yourself.

    Maybe you'll even learn something.

    .logic.


This discussion has been closed.
Advertisement