Find the answer to your Linux question:
Results 1 to 3 of 3
Hi everyone. I am a Linux scripting newbie and and was hoping to get some assistance with a bash script I am working on. I am attempting to write a ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2004
    Posts
    4

    Help w\ bash script


    Hi everyone. I am a Linux scripting newbie and and was hoping to get some assistance with a bash script I am working on. I am attempting to write a bash script to determine if a user specified file is in the current PATH environment variable. If the file is present in the path, I need to then display the filename with the the leading directory specification removed. The script would be ececuted by the syntax of command filename . I was thinking I might be able to include the find command, for example, find -name $1 -print or something similar. Any help to get me headed in the right direction would be greatly appreciated.

    Thanks.

  2. #2
    Linux Guru
    Join Date
    Apr 2003
    Location
    London, UK
    Posts
    3,284
    are you aware of the command:
    Code:
    which
    that does a very similar thing already?

    (see "man which" for details)

    Jason

  3. #3
    Just Joined!
    Join Date
    Jun 2004
    Posts
    4
    Thanks for the help, basename $(which $1) seems to work.

    Along with displaying the filename, I also have to display the filesize in bytes as well as the file permissions in octal in a tab separated list. Ls - l | awk '{print $5}' will give me the filesize in bytes and echo "2i8o`ls -ld file_name|cut -c4,7,10|tr xsST- 01110``ls -ld file_name|cut -c2-10|tr rwsxtST- 11111000-`p"|dc will give me the file permissions in octal, but I am a little confused on how to display this information in a tab separated list?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •