Find the answer to your Linux question:
Results 1 to 5 of 5
Hi. I want to add an operator to a bash script. I know how to write the script for it, but I just don't know how to add the -a ...
  1. #1
    Just Joined!
    Join Date
    Jul 2009
    Posts
    3

    Bash Script Operators

    Hi.

    I want to add an operator to a bash script.

    I know how to write the script for it, but I just don't know how to add the -a part into it.

    this is what I have so far.
    but I want to be able to type trash -a instead of just trash!

    Code:
    #!/bin/sh
    
    read -p "Are you sure you want to remove all files (y/n)? " # asks user to accept [y] or deny [n] deleting all files from dustbin
    
    if [ "$REPLY" == "y" ] # makes an if statment, if statment is true
    then
    mv ~/scripts/dustbin/* ~/scripts/trashCan # do this [true]
    else
    [ "$REPLY" == "n" ] # if statement is false
    exit # do this [false]
    fi
    
    echo "All files have been deleted!"
    can anyone help me out please?

    Joeh.

  2. #2
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    955
    Presumably you want trash -a to do something different from trash.

    Arguments to bash scripts are assigned to $1, $2 and so on. So for trash -a, $1 will have the value "-a". For trash it will be a zero length string. You could test for a non-zero argument by using
    Code:
    [ -n $1 ] && (do something different)
    "I'm just a little old lady; don't try to dazzle me with jargon!"

  3. #3
    Just Joined!
    Join Date
    Jul 2009
    Posts
    3

    Exclamation Moving to chosen directory

    Hey, that was great, thanks

    New problem:
    I am trying to move files from one Directory to another that the user types in their self.

    I know how to use the read command, just not how to get that as the directory.

    Any help appreciated

    Thanks,
    Joeh

  4. #4
    Linux Newbie egan's Avatar
    Join Date
    Feb 2009
    Location
    Mountain View, CA
    Posts
    132
    Quote Originally Posted by SirJoeh View Post
    Hey, that was great, thanks

    New problem:
    I am trying to move files from one Directory to another that the user types in their self.

    I know how to use the read command, just not how to get that as the directory.

    Any help appreciated

    Thanks,
    Joeh
    Well if the user types the directory in correctly, and that input is read in to $REPLY, then you can do:
    Code:
    mv $FILE $REPLY
    where $FILE is the file being moved.

  5. #5
    Just Joined!
    Join Date
    Jul 2009
    Posts
    3
    Thanks a lot! That helped loads!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...