Question

I am writing a script using bash in ubuntu. I am recieving the following error: Saving...

I am writing a script using bash in ubuntu. I am recieving the following error:

Saving long list format of the parent directory to the list_directory.txt
./shell.sh: line 12: list_directory.txt: Permission denied
There are 2 items in the parent directory
I will sort the file in reverse order and save it to reverse_list.txt
sort: cannot read: list_directory.txt: Permission denied
sort: cannot read: list_directory.txt: Permission denied

This is the code:

echo "Saving long list format of the parent directory to the list_directory.txt "
ls -l.. > list_directory.txt

echo "There are $(ls -l .. | wc -l) items in the parent directory"
echo "I will sort the file in reverse order and save it to reverse_list.txt"
sort -r list_directory.txt > reverse_list.txt

Where am I going wrong with the permissions for these files? In addition, is ">" used to write to an existing file or create a new one to write to? I am attempting to learn this through trial and error but because of the permission denied I cannot experiment. Thank you.
echo

Homework Answers

Answer #1

This Error occurs because of the Permissions that you don't have to access files folders.

So to enable your permissions, use the below command

chmod 0777 (path)

where path is parent folder.

ex: path is /user/parent

And then execute your script,
Then it will work without any error.

And '>' symbol is used in the following ways

If the file is not present, It will create a new file and paste all the contents.

If the file is present, it will override the file and paste the contents.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT