User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 456,438 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,650 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 1335 | Replies: 1
Reply
Join Date: Jul 2007
Posts: 1
Reputation: srinivasocp is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
srinivasocp srinivasocp is offline Offline
Newbie Poster

Question script not working in RedHat Linux.

  #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.


#ss23
#usage ss23

echo "enter any filename \c"
read fname
if[!-z "$fname"] then
 if [-r $fname -a -w $fname -a -x $fname]
  then
    echo you have read,wirte and execute permisions to $fname
   else
    echo read,write and execute permisions denied
  fi
else

   echo improper filename
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...
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2007
Posts: 52
Reputation: radoulov is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 5
radoulov's Avatar
radoulov radoulov is offline Offline
Junior Poster in Training

Re: script not working in RedHat Linux.

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

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Shell Scripting Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 1:38 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC