Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Systems > Linux / BSD / OS X
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 02-12-2005, 12:18 PM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
scripting with php: new line

i'm making a shell script with php. example:
Code:
#!/usr/local/bin/php <? echo "hello\n"; echo "world\n"; ?>
it actually prints out the new line characters instead of going to a new line. is there a way to get it to go to the next line with php?
__________________
testing 1 2 3
sde is offline   Reply With Quote
Old 02-12-2005, 12:19 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
nevermind, i was using single quotes in my code .. double quotes works fine.
__________________
testing 1 2 3
sde is offline   Reply With Quote
Old 02-12-2005, 06:15 PM   #3 (permalink)
technobard
Centurion Nova Prime
 
technobard's Avatar
 
Join Date: May 2002
Location: Oak Park, IL (USA)
Posts: 284
technobard is on a distinguished road
Hey, sde.

I was just curious what prompted this. It never occurred to me to use PHP for shell scripting. With the easy database connectivity and other cool features, it could be a good replacement for a lot of Perl stuff.
__________________
It takes 2 points to draw a straight line, but at least 3 points to draw a conclusion.
technobard is offline   Reply With Quote
Old 02-12-2005, 07:41 PM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
i've been using php more and more lately for shell scripting. as you mentioned, database connectivity is the #1 reason, not to mention it's my favorite language.

a while back i'd mainly use it for fun integration with our half-life game servers i help run, but now i use php scripting for clients too. one of them needs several datafeeds generated from their huge product list everyday and php is perfect for that.
__________________
testing 1 2 3
sde is offline   Reply With Quote
Old 02-13-2005, 09:47 AM   #5 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
string interpolation.. Bites me from time to time as well..

I mainly stick to perl for shell script-related tasks, but it certainly makes things easier when you have a chunk of PHP already written that you can use via cron/etc..
__________________
idx is offline   Reply With Quote
Old 02-15-2005, 07:41 PM   #6 (permalink)
Kernel_Killer
Regular Contributor
 
Kernel_Killer's Avatar
 
Join Date: Feb 2003
Location: indisclosed
Posts: 210
Kernel_Killer is on a distinguished road
You can also use C for shell scripting.....
__________________
Network Synapse
Screaming Electron
Kernel_Killer is offline   Reply With Quote
Old 02-15-2005, 08:01 PM   #7 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
really? i didn't know C could be used as a scripting language.

the only drawback of php scripting that i've come across is that it has no user input feature. ( i think ) .. now that would be cool.
__________________
testing 1 2 3
sde is offline   Reply With Quote
Old 02-15-2005, 08:15 PM   #8 (permalink)
technobard
Centurion Nova Prime
 
technobard's Avatar
 
Join Date: May 2002
Location: Oak Park, IL (USA)
Posts: 284
technobard is on a distinguished road
sde, it occurred to me that you only have to intercept stdin to add user input functionality. I found this in a quick search:
Code:
<?php function read($len = 255) { $fp=fopen('php://stdin', 'r'); $input=fgets($fp, $len); fclose($fp); return str_replace(array("\r", "\n"), array('', ''), $input); } echo("Whats your name? "); $name = read(); echo("Hello $name!\n"); ?>
The original link is: PHP User Input Example
It's supposed to be cross platform.
__________________
It takes 2 points to draw a straight line, but at least 3 points to draw a conclusion.
technobard is offline   Reply With Quote
Old 02-15-2005, 08:18 PM   #9 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
oh damn, that is cool thanks !
__________________
testing 1 2 3
sde is offline   Reply With Quote
Old 02-16-2005, 05:04 PM   #10 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
Quote:
Originally Posted by Kernel_Killer
You can also use C for shell scripting.....
Depends on your definition I suppose.. (and willingness to learn C)


sde: PHP's readline support might handy as well.

-r
__________________
idx is offline   Reply With Quote
Reply


Thread Tools
Display Modes

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP vs .NET Redline Lounge 1 11-24-2004 06:10 AM
PHP Comes of Age sde Code Newbie News 0 04-14-2004 11:41 AM
I need to learn PHP Nitro PHP 9 06-28-2003 11:24 AM
VI Editor Tips sde Linux 0 02-17-2003 12:40 AM
cgi script Henry PHP 25 12-30-2002 06:54 AM


All times are GMT -8. The time now is 06:43 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle