Question

In: Computer Science

Write a script that prompts the user for a pathname of a file or directory and...

  1. Write a script that prompts the user for a pathname of a file or directory and then responds with a description of the item as a file along with what the user's permissions are with respect to it (read, write, execute).

Solutions

Expert Solution

Please find the bash script and execution screenshots below.

I have added all the comments for your better understanding.


#reading file/directory path upto its name into path variable

echo -n "Enter your file name or file path or directory name/path: "
read path 

#checking whether file / directory exists or not
#if its present then we will print corresponding permissions
if [ -f "$path" ] || [ -d "$path" ]; then
    echo "$path exists."
    
    #checking for write permission
  [ -w $path ] && W="Permission_to_Write = yes" || W="Permission_to_Write = No"
  #checking for execute permission
  [ -x $path ] && X="Permission_to_Execute = yes" || X="Permission_to_Execute = No" 
  #checking for read permission
  [ -r $path ] && R="Permission_to_Read = yes" || R="Permission_to_Read = No" 
echo -e "$path permissions : \n $W \n $R \n $X"

#if path is invalid then we will print does not exist
else 
    echo "$path does not exist in the given path."
fi

For file name abc.txt:

for directory: jjdj

for nested path: jjdj/x


Related Solutions

Write a bash script file that tests each file entry in the current directory. It should...
Write a bash script file that tests each file entry in the current directory. It should determine if it is a file or directory. If it is a file, it will determine if it is readable or not. If it is readable, it will display only the first 4 lines to the terminal in sorted order (just sort the first 4 lines). If it is a directory, it should display the contents of that directory (the files and subdirectories). NOTE:...
Write a program that prompts the user to enter a file name, then opens the file...
Write a program that prompts the user to enter a file name, then opens the file in text mode and reads names. The file contains one name on each line. The program then compares each name with the name that is at the end of the file in a symmetrical position. For example if the file contains 10 names, the name #1 is compared with name #10, name #2 is compared with name #9, and so on. If you find...
⦁   Write a Bash script that prompts for user input and reads a string of text...
⦁   Write a Bash script that prompts for user input and reads a string of text from the user. If the user enters a no null (no empty) string, the script should prompt the user to re-enter again the string; otherwise should display the string entered “. ⦁   Given an array of the following four integers (3, 5, 13, 14); write a Bash script to display the second and all elements in the array.    ⦁   Write a short Bas...
Using MATLAB or Octave, Write a script that prompts the user for the coordinates of three...
Using MATLAB or Octave, Write a script that prompts the user for the coordinates of three points A, B, and C, namely (xA, yA), (xB, yB), (xC, yC), forming a triangle, storing each in a variable (for a total of 6 variables). The script should then calculate the centroid G = (xG, yG) using xG = xA+xB+xC 3 and yG = yA+yB+yC 3 , storing each in a variable. Finally, the script should print all four points. Sample output: Enter...
Using MATLAB or Octave, Write a script that prompts the user for a multiplier, storing it...
Using MATLAB or Octave, Write a script that prompts the user for a multiplier, storing it in the variable fMultiplier. The script should them prompt the user for a number, storing it in the variabl fIn. The script should then calculate the product of these two variables, saving the result to another variable fOut, and printing it. The script should then repeat the prompt for fIn, calculation, and output twice more, using the same variable fIn and fOut all three...
Using MATLAB or Octave, Write a script that prompts the user for a minimum and maximum...
Using MATLAB or Octave, Write a script that prompts the user for a minimum and maximum real number, then generates and prints a random number in the requested range. The script should then do the same for an integer range. Sample output: Enter a minimum real value: 0.5 Enter a maximum real value: 30 A random number in the range ( 0.5000, 30.0000 ) is 1.7851 Enter a minimum integer value: -10 Enter a maximum integer value: 20 A random...
Write a program that prompts the user for a file name, make sure the file exists...
Write a program that prompts the user for a file name, make sure the file exists and if it does reads through the file, count the number of times each word appears and then output the word count in a sorted order from high to low. The program should: Display a message stating its goal Prompt the user to enter a file name Check that the file can be opened and if not ask the user to try again (hint:...
1. Write a program that prompts the user for a filename, then reads that file in...
1. Write a program that prompts the user for a filename, then reads that file in and displays the contents backwards, line by line, and character-by character on each line. You can do this with scalars, but an array is much easier to work with. If the original file is: abcdef ghijkl the output will be: lkjihg fedcba Need Help with this be done in only PERL. Please use "reverse"
Write a Flask app in which a Python script prompts the user to enter a string...
Write a Flask app in which a Python script prompts the user to enter a string and then that string, as entered, gets displayed on an otherwise blank HTML file, called output.html. Show the Python/Flask code and the html code of the output.html file, one below the other as part of your answer.
Using MATLAB or Octave, use documenting code to Write a script that prompts the user for...
Using MATLAB or Octave, use documenting code to Write a script that prompts the user for a minimum and maximum real number, then generates and prints a random number in the requested range. The script should then do the same for an integer range. Sample output: Enter a minimum real value: 0.5 Enter a maximum real value: 30 A random number in the range ( 0.5000, 30.0000 ) is 1.7851 Enter a minimum integer value: -10 Enter a maximum integer...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT