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 ...
- 07-19-2009 #1Just 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!
can anyone help me out please?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!"
Joeh.
- 07-19-2009 #2
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!"
- 07-21-2009 #3Just Joined!
- Join Date
- Jul 2009
- Posts
- 3
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
- 07-21-2009 #4
- 07-21-2009 #5Just Joined!
- Join Date
- Jul 2009
- Posts
- 3
Thanks a lot! That helped loads!!!


Reply With Quote
