LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-16-2003, 07:41 PM   #16
DavidPhillips
LQ Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,163

Rep: Reputation: 58

Ok scratch the above, I have found the problem

you need quotes not double qoutes or else you get an error with the #!/usr/bin/php part of it due to the "!" I guess.

here is an example

[david@zeus david]$ echo file1 > 1.php

[david@zeus david]$ echo file2 > 2.php

[david@zeus david]$ echo file3 > 3.php

[david@zeus david]$ cat prepend
#!/bin/sh
for file in `ls $2`
do
mv $file tmp
echo $1 > $file
cat tmp >> $file
rm tmp
done

[david@zeus david]$ cat *.php
file1
file2
file3

[david@zeus david]$ sh ./prepend "#!/usr/bin/php" "*.php"
bash: !/usr/bin/php": event not found

[david@zeus david]$ sh ./prepend '#!/usr/bin/php' '*.php'

[david@zeus david]$ cat *.php
#!/usr/bin/php
file1
#!/usr/bin/php
file2
#!/usr/bin/php
file3
 
Old 07-17-2003, 09:10 AM   #17
dalai
LQ Newbie
 
Registered: Jul 2003
Location: Paris
Distribution: MandrakeLinux
Posts: 6

Rep: Reputation: 0
you might like to use Perl.
All on one single line, it looks like

for i in *.php;do perl -pi -e '$_="\#\!\/usr\/bin\/php\n$_" if $. == 1' $i ;done

ie for all the first lines in all php files replace this first line by what you want
 
Old 07-17-2003, 09:27 AM   #18
dalai
LQ Newbie
 
Registered: Jul 2003
Location: Paris
Distribution: MandrakeLinux
Posts: 6

Rep: Reputation: 0
Just an addition, if you do not like Perl, maybe you can stay with Bash

for i in *.php;do (tac $i ;echo '#!/usr/bin/php')>toto;tac toto >$i; done

Of course in the end you are left with a temp file toto you'll have to remove (which is not the case via Perl
 
Old 07-17-2003, 12:35 PM   #19
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 48
No temporary files, one line in bash:
Code:
for i in *.php; do echo '#!/bin/sh' | cat - $i | dd of=$i;done
 
Old 07-17-2003, 01:28 PM   #20
bobdinkel
LQ Newbie
 
Registered: Mar 2003
Location: Austin, TX
Posts: 6

Original Poster
Rep: Reputation: 0
Hot damn! I got it to work! Just so you folks know, there were no files with spaces in their names. Initially, I did copy and paste your script, but couldn't get it to work. I added the "#!/usr/bin/php" in double quotes in place of $1 out of desperation. I went back and changed those to single quotes and it worked. But I still had to hard-code the values. It was still choking on the first argument before I did that.
Thanks. I very much appreciate your help. Mighty neighborly.
 
Old 07-17-2003, 03:21 PM   #21
DavidPhillips
LQ Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,163

Rep: Reputation: 58
cool


you gotta love allthe possibilities

Last edited by DavidPhillips; 07-17-2003 at 03:23 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash: <command name> command not found smash Programming 5 03-13-2006 09:48 AM
The ! bash command. How do I use it? funkynesh Linux - Newbie 2 10-12-2005 09:36 PM
bash: command not found intels_ss Linux - Newbie 5 07-20-2005 08:41 PM
-bash: ls: command not found jchun Linux - General 3 11-02-2004 11:11 AM
bash command question BajaNick Linux - Software 8 10-05-2003 08:56 PM


All times are GMT -5. The time now is 09:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration