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 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...
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...
Write a program that creates a file called "data.dat" in the current directory. Prompt the user...
Write a program that creates a file called "data.dat" in the current directory. Prompt the user for five numbers, and write them, one at a time, on both the screen and into the file. Close the file, then open it again for reading only, and display the contents on the screen. Handle error conditions that may occur. Please Need this to be done in PERL. Thanks
Task 2.5: Write a script that will ask the user for to input a file name...
Task 2.5: Write a script that will ask the user for to input a file name and then create the file and echo to the screen that the file name inputted had been created 1. Open a new file script creafile.sh using vi editor # vi creafile.sh 2. Type the following lines #!/bin/bash echo ‘enter a file name: ‘ read FILENAME touch $FILENAME echo “$FILENAME has been created” 3. Add the execute permission 4. Run the script #./creafile.sh 5. Enter...
Write a brief shell script that will take in a specific file name, prompt the user...
Write a brief shell script that will take in a specific file name, prompt the user whether they would like to gzip, bzip2, or xz compress the file. Depending on response, the script then ought to compress the provided file with the corresponding method
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT