Advertisement
obernardovieira

Get filetype (directory, executable or text file)

Mar 21st, 2015
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.33 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. otipo=$(ls -l | grep "$@$" | cut -c 1,4)
  4.  
  5. if test "otipo" = ""
  6. then
  7.     echo "$@ -> doesn't exist!"
  8. else
  9.     if test "${otipo:0:1}" = "d"
  10.     then
  11.         echo "$@ -> is a directory!"
  12.     else
  13.         if test "${otipo:1:2}" = "x"
  14.         then
  15.             echo "$@ -> is an executable file!"
  16.         else
  17.             echo "$@ -> is a text file!"
  18.         fi
  19.     fi
  20. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement