Guest User

Untitled

a guest
Nov 21st, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #1) make a getname function that will prompt for filename
  2. function getname(){
  3. trap control_c SIGINT
  4. local fname=$1;
  5.  
  6. #if there is no input prompt user for file name
  7. if [ ! $1 ]; then
  8. read -p "Enter a file name: " fname;
  9. fi;
  10.  
  11. #until grep is given a valid file name
  12. until ( grep -E '^[a-zA-Z_]w+$' <<< "$fname" > /dev/null 2>&1); do
  13.  
  14.  
  15.  
  16.  
  17.  
  18. #this is were the error is
  19. if echo "$fname" | grep -E '/';
  20.  
  21.  
  22.  
  23.  
  24.  
  25. then #this tests if fname is a file directory
  26. echo "Paths are not a legal file name.";
  27. fi;
  28. read -p "Enter a legal file name: " fname;
  29. done
  30. echo "$fname"
  31. }
Add Comment
Please, Sign In to add comment