Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Unix -- When you run a program from the command line, the Linux system searches

ID: 3815710 • Letter: U

Question

Unix --

When you run a program from the command line, the Linux system searches a series of folders looking for that le. Those folders are dened in the PATH environment variable. If you want to nd out just what executable les are available on your system for you to use, just scan all the folders in the PATH environment variable. That may take some time to do manually, but it’s a breeze working out a small shell script to do that.

Call your script lab12.2

To get you started, the rst step is to create a for-loop to iterate through the folders stored in the PATH environment variable. When you do that, don’t forget to set the IFS separator character:

Explanation / Answer

#!/bin/bash

# path is represented like path1:path2:path3:path4 and so on
# so we set IFS to : so that it is taken as proper separator
IFS=":"

# now we find all files in the directories represented by path and then printing them
for file in `find $PATH -maxdepth 1 -type f`; do
echo $file
done

Please rate positively if this solved you rquestion.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote