The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
unix begginers jao_madn UNIX for Dummies Questions & Answers 4 10-08-2007 09:06 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-06-2008
hadar hadar is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 3
a begginers question

hey
i'm very much new to unix
i'm trying to write a script which goes through given files and checks if the files begin with # and if they are executable
my problem is that when i try to check the result of my query i'm getting nada
let me explain :
when i write
if (`file $i | grep 'executable' `=~ ?*)

or
if (`head -1 $i | grep '^#' ` != ``)

i'm getting weird results
i'm guessing my sintax is way off here...
any suggestions on the proper syntax for checking if the return value of this query isn't NULL...?

thanks in advance
  #2 (permalink)  
Old 01-06-2008
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
You could

(a) check if executable by "test -x filename"

(b) get the very first character using "dd if=filename bs=1 count=1"
  #3 (permalink)  
Old 01-06-2008
hadar hadar is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 3
sorry for being such a pain,
but i'm supposed to specificly check that the outcome "file filename"
has the word executable in it...
and i didn't quite get the (b) part -
should i use it as a condition like so:

if ("dd if=file name bs = 1....." == "#")

(as i said...very new to unix )
  #4 (permalink)  
Old 01-06-2008
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by hadar View Post
but i'm supposed to specificly check that the outcome "file filename" has the word executable in it...
Who says?

Code:
if test -x $FILE
then
    FIRSTCHARS=`dd if=$FILE bs=1 count=2`
    if test "$FIRSTCHARS" = "#!"
    then
          echo starts with "$FIRSTCHARS"
    fi
fi

Code:
file $FILENAME | grep executable >/dev/null
if test "$?" = "0"
then
     echo file says its executable
fi

Last edited by porter; 01-06-2008 at 07:41 PM..
  #5 (permalink)  
Old 01-06-2008
hadar hadar is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 3
thank you very much, now it's all very clear
  #6 (permalink)  
Old 01-06-2008
frank_rizzo frank_rizzo is offline Forum Advisor  
Resident BOFH
  
 

Join Date: Dec 2007
Posts: 427
Quote:
Originally Posted by porter View Post
Who says?
I bet his teacher says...


fyi to the poster begginer is really spelled as beginner
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:04 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0