Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Help with Bash Scripts - Solved
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
foxsin
n00b
n00b


Joined: 22 Dec 2003
Posts: 3
Location: Near the Woods

PostPosted: Fri Jan 02, 2004 4:51 am    Post subject: Help with Bash Scripts - Solved Reply with quote

When I write my own sh/bash script and run it, it always outputs the script source before running the script itself.

What do I need to do/set so it just runs without displaying the script itself?

Thanks in advance
_________________
This is paradise...enjoy!


Last edited by foxsin on Fri Jan 02, 2004 6:02 am; edited 1 time in total
Back to top
View user's profile Send private message
k9
Apprentice
Apprentice


Joined: 28 Sep 2003
Posts: 160
Location: Salt Lake City, USA

PostPosted: Fri Jan 02, 2004 5:08 am    Post subject: Reply with quote

Can you provide a copy of one of the scripts you are having problems with?

Creating a file such as this, called test.sh...

Code:
#!/bin/bash
 
echo Hello world.


...then running this to make it directly executable:

Code:
chmod a+x test.sh


And then running the program:

Code:
$ ./test.sh
Hello world.


...should work.
Back to top
View user's profile Send private message
foxsin
n00b
n00b


Joined: 22 Dec 2003
Posts: 3
Location: Near the Woods

PostPosted: Fri Jan 02, 2004 5:33 am    Post subject: Reply with quote

Sure here is the code I have run

Code:

#!/bin/bash
for file in *
 do
 if grep -l FRED $file
 then
  more $file
 fi
done
exit 0


I have a dummy file in the directory with the word FRED in it

The output is as follows:
Code:

$fred.sh
#!/bin/bash
for file in *
do
if grep -l FRED $file
then
more $file
fi
done
exit 0

dummy.txt
This file should be called FRED
$


I tried your example and that one worked, but mine did not. I have just put it back in as I had tabs to format the script and replaced them with spaces and now the script runs first then the source is outputted as shown below:
Code:

$fred.sh
#!/bin/bash

dummy.txt
This file should be called FRED

for file in *
do
if grep -l FRED $file
then
more $file
fi
done
exit 0

$


I'm even more confused!... I am learning from a book and there is no mention of this, so I dont know if it is supposed to do this or if I need to set something.
_________________
This is paradise...enjoy!


Last edited by foxsin on Fri Jan 02, 2004 5:50 am; edited 1 time in total
Back to top
View user's profile Send private message
k9
Apprentice
Apprentice


Joined: 28 Sep 2003
Posts: 160
Location: Salt Lake City, USA

PostPosted: Fri Jan 02, 2004 5:46 am    Post subject: Reply with quote

I think it's working exactly as it should. :D

It looks like this running all of the files that contain the string "FRED" through 'more'. Since fred.sh has "FRED" in it (and it's in *), it gets run through 'more' as well.
Back to top
View user's profile Send private message
foxsin
n00b
n00b


Joined: 22 Dec 2003
Posts: 3
Location: Near the Woods

PostPosted: Fri Jan 02, 2004 5:59 am    Post subject: Reply with quote

To quote a famous actor.

Quote:

'Doh!'
- Homer Simpon (various)


Its obvious when you point it out :D

Many thanks.
_________________
This is paradise...enjoy!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum