unix-programming

Using Unix Process Controll Methods in Ruby

Ryan Tomayko touched off quite a fire storm with this post about using Unix process control commands. We should be doing more of this. A lot more of this. I'm talking about fork(2), execve(2), pipe(2), socketpair(2), select(2), kill(2), sigaction(2), and so on and so forth. These are our friends. They want so badly just to help us. ...

Unix programming. Not sure how to use the passwd struct

I've done some research and I'm still struggling with the passwd structure. http://www.opengroup.org/onlinepubs/000095399/basedefs/pwd.h.html I need to obtain the user ID however I dont think I'm using understanding it at all. int getpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **); This method call returns a point t...

Setting up OS X for Android development. OR Are *nix environments intentionally prohibitive?

I'm trying to start doing Android development on OS X (trying is the key here). I've read all the fun stuff at http://developer.android.com/sdk/index.html. I get the basics, install the JDK, Eclipse, the Android SDK, the Eclipse plugin and ADT. That's a lot to do but I get the point of each step, so, OK, fine. Then there are a millio...

UNIX Learner? Books? Websites?

I am looking to buy a book on UNIX for programming, shell scripts and overall about UNIX, any useful UNIX tutorial websites or books you guys recommend? ...

Writing application for both Unix and Windows

I'll write a program for Interactive UNIX (http://en.wikipedia.org/wiki/INTERACTIVE%5FUNIX). But in a year it will be ported to Windows. I'll write it in ANSI C and/or SH-script. When it runs on Windows it will be run as a Windows service. How do I make it as easy as possible for me? I want to change as little as possible when I port it...

Book Recommendation for modern X11 Unix GUI programming?

I have the old 8book O'Reily Serious "The X Resources" in my bookshelf bought about 15 years ago. Is there any book which is explaining the new technologies and X11 extensions like XDnD, Xinerama, XCursor, XRandR, XRender, XIM + Input Methods etc. maybe with a chapter (but not more) of GTK and QT. I'm not even asking for Compiz and ot...

Unix Script not running in Java using Process Runtime

Hello All... I am developing an application where i required to run some of the scripts of unix from Java Code. Platform i am using is Unix, Tomcat 5.5.. For that, My Sample Code is as follows : Runtime runtime = Runtime.getRuntime(); Process proc = runtime.exec("netstat -i|tail -n +3|cut -d ' ' -f1"); System.out.println("exitValue =...

mac osx development environment

i have a unix c programming assignment in which i do some advanced C network programming.this is my first step into advance programming. so i was wondering what is the best combination of tools for this on a mac. using an IDE like Eclipse is how i'd normally do it but i have to make my own makefiles and stuff. so i would like to learn ho...

127 Return code from $?

What is the meaning of return value 127 from $? in UNIX. ...

Moving from VMS to Unix

Dear Stackoverflow, Once upon a time, a team of guys sat down and wrote an application in C, running on VMS on a VAX. It was a rather important undertaking and runs a reasonably important back-end operation at LargeCo. This whole shebang works so well that twenty-five years later it's still chugging along and doing it's thing. Time pa...

How can I use arrays in unix shell?

Hi, I use code in !/bin/sh like this: LIST1="mazda toyota honda" LIST2="2009 2006 2010" for m in $LIST1 do echo $m done As you can see this currently prints out only the make of the car. How can I include the year to each "echo" based on the same positions so that I get results like: mazda 2009 toyota 2006 honda 2010 ? ...

is_number function doesn't work for me - unix shell

When I pass in 2009 as a arg to this shell function it returns 0, why? isyear() { case $arg in [0-9][0-9][0-9][0-9]) NUM=1 ;; *) NUM=0 ;; esac echo $arg } ...

How do I process something like this in unix shell?

Hi All, What would be the best approach to process a call like this to my shell script? ./cars Mazda Toyota 2010 Honda BMW VW 2009 So that it prints out: Mazda 2010 Toyota 2010 Honda 2009 BMW 2009 VW 2009 I can't use arrays because it's the most simple version of shell so it doesn't support them. Any ideas? ...

If condition issue in shell

Hi all, I'm trying to detect whether a string holds a dash but nothing seems to work for me (I'm new to shell). if [ "$m" -eq "-" ] then echo "has dash" else echo "has no dash" fi ...

Case statement in shell - problem

Hi, I'm completely new to shell and I'm trying to include a case where the function's arg #1 is greater or equal 12 then it should return 1. But the below doesn't work. case $1 in -ge 12) NUM=1 ;; *) NUM=0 ;; esac echo $NUM ...

Problem with including an "image" in shell program.

Hi All, I'm writing a program where at some point in my loop I want to print to output whatever is stored in a separate file (an image). But if I code it like this: for c in $LIST do clear ./image.0 done And the "image.0" file contains only an image like this: +----+ | | | | | | | ======== Then when I run my program I ...

How to set read command to execute without having to press Enter button in shell?

Hi All, I use the below code to assign a given by the user character to variable G: read G However in order to move forward with executing of my script I need to press enter button. Is it possible to set the read command somehow that it show process forward to the next line immediately after it receive the one letter from stdin? ...

Exit entire program from a function call in shell?

Hi, I have a function which I use in my shell script and based on a certain condition I'd like to call "exit 0" in that function so that the entire script exits. But for some reason the program still runs after calling exit 0 in the function. Why? check() { printf "Would you like to try again?\n" read S if [ "$S" = "y" ] then ...

How to detect a filename within a case statement - in unix shell?

Hi I coded the below code and if no -l or -L option is passes to the script I need to assume (detect) whether a filename was passed as a param. The below third condition only matches if filename is one lowercase character. How can I make it flexible to match upper and lower case letters or variable length of the string? while [ $# -gt...

What's the best way to edit a text file record using shell?

I have data file that stores records like this: make=honda|model=civic|color=red make=toyota|model=corolla|color=blue What would be the best way to detect (based on the make field) whether a given make exists in the file and then replace it with a new record? (Using shell script) ...