should be in Linux, please
Write a shell program named A1L21
Your program should set permissions for a file whose name is given as
an argument to your program. The permissions must be changed using a
SINGLE chmod command, and must be set to EXACTLY rw for owner and group
and x for others.
Your program should NOT show any error messages on the screen, even if
the given file does not exist, etc.
Code inside the shell program-
#!/bin/bash
chmod 661 $1 2> /dev/null
Explanation -
chmod - used to change file permissions
661 - represents the three sets of permission
(owner, group and other). 6 is for read and write permission. 1 is
for execute permission.
$1 - this has the argument given to the shell
program.
2> /dev/null this part is used to suppress the
error messages when a file does not exist etc.
> this is the redirect operator .
2 this is a reference to standard error output
stream.
2> redirect the output stream.
/dev/null this is a null device it eats up any
input provided to it.
by combining these we can throw away the output error
messages.
** Tested in Ubuntu **
Get Answers For Free
Most questions answered within 1 hours.