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

Reply
 
LinkBack Thread Tools Display Modes
Old 02-12-2005, 01:18 PM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,530
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?
__________________
Mike
sde is offline   Reply With Quote
Old 02-12-2005, 01:19 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,530
sde is on a distinguished road
nevermind, i was using single quotes in my code .. double quotes works fine.
__________________
Mike
sde is offline   Reply With Quote
Old 02-12-2005, 07:15 PM   #3 (permalink)
technobard
Centurion Nova Prime
 
technobard's Avatar
 
Join Date: May 2002
Location: Oak Park, IL (USA)
Posts: 287
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, 08:41 PM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,530
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.
__________________
Mike
sde is offline   Reply With Quote
Old 02-13-2005, 10: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, 08: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, 09:01 PM   #7 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,530
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.
__________________
Mike
sde is offline   Reply With Quote
Old 02-15-2005, 09:15 PM   #8 (permalink)
technobard
Centurion Nova Prime
 
technobard's Avatar
 
Join Date: May 2002
Location: Oak Park, IL (USA)
Posts: 287
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, 09:18 PM   #9 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,530
sde is on a distinguished road
oh damn, that is cool thanks !
__________________
Mike
sde is offline   Reply With Quote
Old 02-16-2005, 06: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

Bookmarks

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

BB 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 07:10 AM
PHP Comes of Age sde Code Newbie News 0 04-14-2004 12:41 PM
I need to learn PHP Nitro PHP 9 06-28-2003 12:24 PM
cgi script Henry PHP 25 12-30-2002 07:54 AM


All times are GMT -8. The time now is 12:22 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting