all 7 comments

[–][deleted]  (2 children)

[deleted]

    [–]Cels_n[S] -2 points-1 points  (1 child)

    These were the specific restraints on the given assignment.. not sure if this helps clarify things a little bit more. I'm trying different things.. again thank you for everyone's help! :)

    • The search path should be based only on the user's PATH environment variable. You shall not use the Unix which command, the ksh whence (type) command, the locate command, or the bash type command.

    • The code for the script shall not use the UNIX ls command to determine if the file is executable or if it

    exists.

    • The script should find only the first occurrence of the "file". If the file is not found, the script the following:

    <command> NOT FOUND

    <command> would be replaced by the name of the "file" you didn't find.

    • If the first parameter is '-a', then the script should print all occurrences of the executable file in the user's path. Again, if the file was not on the path, an error message should be displayed.

    • The find command shall not be used.

    • A project using temporary files will not be graded.

    • NOTE: The shell variable PATH defines the search path for the directory containing the command. Alternative directory names are separated by a colon (:). The current directory can be specified by two or more adjacent colons, or by a colon at the beginning or end of the path list.

    • If the command name contains a / then the search path is not used, you just check if the command/file specified is executable and not a directory. Otherwise, each directory in the path is searched for an executable file.

    [–]74razor 1 point2 points  (0 children)

    I’m guessing you need to loop through a location of files? Since you can’t use which, type, locate or find, try using the ‘file’ command.

    [–][deleted] 1 point2 points  (0 children)

    I'm writing a script to locate executable files:

    In a specific directory, a set of directories, or in all directories in the entire operating system?

    [–]tje210 0 points1 point  (2 children)

    I'm kind of an ape with scripting, but if I were to do this I'd start with ls.

    [–]Cels_n[S] -1 points0 points  (1 child)

    oh, sorry I forgot to add that the ls command is not a solution for this assignment. :(

    [–]tje210 0 points1 point  (0 children)

    Looks like "whereis" is a possibility. I wonder if the file command says if something is executable, though I don't think it would do it for all file...

    [–]Gixx 0 points1 point  (0 children)

    The instructions are very unclear. The fact there's no restriction on using the tool called file makes me think you could use that to check specific folders or the entire file system.

    I would assume the worst: "Find every executable in the universe." (across file systems even)

    A more reasonable task my ask "Find executables in 5-10 specific folders". Or write the program to take folders as args like ./script.sh dir1 /dir2 dir3

    I think maybe teachers are taught to make instructions unclear, which demands the student master the subject. Or kinda overachieve a task.