a begginers question


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers a begginers question
# 1  
Old 01-06-2008
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  
Old 01-06-2008
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  
Old 01-06-2008
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 Smilie)
# 4  
Old 01-06-2008
Quote:
Originally Posted by hadar
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  
Old 01-06-2008
thank you very much, now it's all very clear Smilie
# 6  
Old 01-06-2008
Quote:
Originally Posted by porter
Who says?
I bet his teacher says...


fyi to the poster begginer is really spelled as beginner
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Ls -l question

Hi, When doing ls -l, is it right to assume that all files with the date and time on it are files that are created/modified on the current year? Is there any way to display the creation/modified date of a file that are not created/modified in the current year? (4 Replies)
Discussion started by: newbie_01
4 Replies

2. Shell Programming and Scripting

A question

Hi, I'm new to unix and got struck here.Can any one help me out.My question is .. is the command if ; then echo "do some stuff" fi correct? Thanks in advance abhijeet (18 Replies)
Discussion started by: Abhijeet_Atti
18 Replies

3. Programming

C++ little question

Hi, I am doing a C++ self-study and I got stuck with this problem. I want to have a code that asks the suer to enter two numbers and then it lists the numbers between these two numbers. It has also to print a message if these two numbers are equal. Here is what I wrote: #include <iostream>... (11 Replies)
Discussion started by: faizlo
11 Replies

4. UNIX for Dummies Questions & Answers

Help me these Question??

1. How the Unix system identify the Other User to access for file permission? 2. What command we use to convert the extension of a file name? 3. What command use to convert other editing file to Unix based text file? Please answer of these Question???Its necessary for me?? (3 Replies)
Discussion started by: pradipta_pks
3 Replies

5. UNIX for Dummies Questions & Answers

Vi Question

Hi Guys I have a quick question I have a file that is approx 1.5 million lines long of which most of the lines start with INFO: some info INFO: some more info INFO: etc I want to remove these lines I was thinking along the lines of :%s/INFO*//g but this does not work None... (6 Replies)
Discussion started by: grahambo2005
6 Replies

6. UNIX for Dummies Questions & Answers

Question

I need to write a script file that will tell me the largest number in a group of numbers. ANy help is greatly appreciated (2 Replies)
Discussion started by: twan
2 Replies

7. Shell Programming and Scripting

question

how do i write a script that'll open what i entered and scan it for a certain line of text. for example, i enter a filename (that exists) and in that file i want to scan a certain word that'll show how much of that word appears throughout the file. (2 Replies)
Discussion started by: mrhenry
2 Replies

8. UNIX for Dummies Questions & Answers

unix begginers

hi im a unix system beginner i would like to write a script that will run as follows 1 it will read all process including what they are doing 2 it will list all the processes that were idle or not consuming space in the VMSTAT command like in the cpu or memory coloum so i can kill those... (4 Replies)
Discussion started by: jao_madn
4 Replies

9. UNIX for Dummies Questions & Answers

Next Question:

what is the function of swap in linux why i have to create apsolutely a particion for the swap when i install (i installed lnx4win mandrake and made an automat. disk particion and the install program one of my disk partitions that was 3gb devidet in 4 one native 700mb swap 600mb and the others i... (1 Reply)
Discussion started by: user666
1 Replies
Login or Register to Ask a Question