I have an assignment due on Tuesday and I have to create a command that will make it easier on noobs to change permissions and delete files, etc.
I call this command ft.
I have a problem. I created an option called -n which will change the file's permission and create the file if it doesn't exist. If the file exists he won't be able to change it. That's not important anyway. I am stuck at one part where we have to change the permissions of all the files in the directory if the user doesn't enter a file to create. How do I do this?
here is my code:
Expand|Select|Wrap|Line Numbers
- declare option=$1
- declare file=$2
- declare permission
- if (( $option == -n ))
- then
- permission=$2
- file=$3
- ls | grep -q $file
- if (( $? == 0 ))
- then
- echo File already exists.
- permission=$3
- file=$2
- else
- touch $file
- chmod $permission $file
- echo File created. It is called $file.
- permission=$2
- file=$3
- fi
- fi