script not working in RedHat Linux.

Reply

Join Date: Jul 2007
Posts: 1
Reputation: srinivasocp is an unknown quantity at this point 
Solved Threads: 0
srinivasocp srinivasocp is offline Offline
Newbie Poster

script not working in RedHat Linux.

 
0
  #1
Jul 12th, 2007
Hi All,

The following script checks whether the filename is correct then the script proceeds to check whether you have read,write and execute permisiions to the file and displays an approriate message.


Shell Scripting Syntax (Toggle Plain Text)
  1. #ss23
  2. #usage ss23
  3.  
  4. echo "enter any filename \c"
  5. read fname
  6. if[!-z "$fname"] then
  7. if [-r $fname -a -w $fname -a -x $fname]
  8. then
  9. echo you have read,wirte and execute permisions to $fname
  10. else
  11. echo read,write and execute permisions denied
  12. fi
  13. else
  14.  
  15. echo improper filename
  16. fi

when i run this script and give the filename 'test' it is showing the following error.


s23:line 3: if[!-z test]: command not found
s23:line 4: if [-r test -a -w $fname -a -x test] : command not found
s23:line 5:syntax error near unexpected token 'then'
i have seen this program in a shell scripting book and tried it but it has shown the above said error. '-z ' returns true if the lenght of the string is zero(this could be in Unix). what would be the equivalent command in Redhat linux. I am using Redhat llinux 9 version.

Please advice.

Thanks
Srini...
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 54
Reputation: radoulov is an unknown quantity at this point 
Solved Threads: 5
radoulov's Avatar
radoulov radoulov is offline Offline
Junior Poster in Training

Re: script not working in RedHat Linux.

 
0
  #2
Jul 13th, 2007
Check your syntax: the construct is if [ ! or [ -r (note the spaces).
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC