| View previous topic :: View next topic |
| Author |
Message |
foxsin n00b


Joined: 22 Dec 2003 Posts: 3 Location: Near the Woods
|
Posted: Fri Jan 02, 2004 4:51 am Post subject: Help with Bash Scripts - Solved |
|
|
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 |
|
 |
k9 Apprentice


Joined: 28 Sep 2003 Posts: 160 Location: Salt Lake City, USA
|
Posted: Fri Jan 02, 2004 5:08 am Post subject: |
|
|
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:
And then running the program:
| Code: | $ ./test.sh
Hello world. |
...should work. |
|
| Back to top |
|
 |
foxsin n00b


Joined: 22 Dec 2003 Posts: 3 Location: Near the Woods
|
Posted: Fri Jan 02, 2004 5:33 am Post subject: |
|
|
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 |
|
 |
k9 Apprentice


Joined: 28 Sep 2003 Posts: 160 Location: Salt Lake City, USA
|
Posted: Fri Jan 02, 2004 5:46 am Post subject: |
|
|
I think it's working exactly as it should.
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 |
|
 |
foxsin n00b


Joined: 22 Dec 2003 Posts: 3 Location: Near the Woods
|
Posted: Fri Jan 02, 2004 5:59 am Post subject: |
|
|
To quote a famous actor.
| Quote: |
'Doh!'
- Homer Simpon (various)
|
Its obvious when you point it out
Many thanks. _________________ This is paradise...enjoy! |
|
| Back to top |
|
 |
|