unix-programming

how to create a array in unix shell programming

how to create a array in unix shell programming ? and i have to excute the program still i press a key similar to do u want to continue option ...

data validation for date data type in unix ?

for eg if i m getting various inputs from keyboard ie Book accession number, Subject code Book_id , Author , Year of Publication, Title of the book, Publisher’s name, Price, and i want do validations such that year of publication must be before 1996, Book_id must be unique, Publisher, Author and the title of the Book cannot be enter...

What is wrong in this code

Here i have got various inputs from keyboard and checked these validations Book_id must be unique. Subject code can only be either UNIX or C.The Shelll i work is bash i got the following errors ./test.sh: line 5: declare: `=0': not a valid identifier /test.sh: line 13: unix: command not found ./test.sh: line 92: syntax error: un...

How to detect null values in shell?

HI all, I wrote this code but it doesn't catch any of the two variables being null, why? echo "$var1 - $var2" if [ "$var1" == ""] || [ "$var2" == ""] then echo "Incomplete data" exit 1 fi The initial echo prints nothing for the variables when I run my script so the if statement should work right? But it doesn't for some reason. ...

why redirecting to same file results in a empty file in unix

Hi, if i redirect to same file it places null in the resultant file. sed 's/abd/def/g' a.txt > a.txt i know it put null in to the file. But can anyone explain why? ...

How to use loops statements in unix shell scripting

How to use loop statements in unix shell scripting for eg while ,for do while. I'm using putty server. ...

Using logical OR (||) in C-Shell

I have a C-Shell code where I use the following command: if($#arr == 0 || $arr[1] == "test1") then It outputs an error message saying "tcsh: arr: Subscript out of range." obviously because the first condition is true. Is it possible to force it to ignore the second condition if the first condition is true? ...

Reason for SIGPIPE

I have an application running on Linux, catching signals and reporting them to syslog. This application frequently reports SIGPIPE events with no apparent reasons The application is running in the background, as daemon. The signals occur at idle times with no apparent network/socket connections. The application frequently reads from an...

Tutorials for setting up a robust small-to-medium project *nix build

I'm mostly a spoiled Windows + Visual Studio (or Borland C++ or whatever, in the past) developer. Although my first contact with Unix was around 20 years ago, and I've used Linux on-and-off for some years, I have only a very limited idea of how to set up a build on a *nix system. For example, I'm OK with the basics of make - I can get a...

How can I tell if a file is older than 30 minutes from /bin/sh?

How do I write a script to determine if a file is older than 30 minutes in /bin/sh? Unfortunately does not stat exist in the system. It is an old Unix system, http://en.wikipedia.org/wiki/Interactive_Unix Perl is unfortunately not installed on the system and the customer does not want to install it, and nothing else either. ...

how to truncate long matching lines returned by grep or ack

I want to run ack or grep on html files that often have very long lines. I don't want to see very long lines that wrap repeatedly. But I do want to see just that portion of a long line that surrounds a string that matches the regular expression. How can I get this using any combination of unix tools? ...

select part of filename using regex

I got a file that looks like dcdd62defb908e37ad037820f7 /sp/dir/su1/89/asga.gz 7d59319afca23b02f572a4034b /sp/dir/su2/89/sfdh.gz ee1d443b8a0cc27749f4b31e56 /sp/dir/su3/89/24.gz 33c02e311fd0a894f7f0f8aae4 /sp/dir/su4/89/dfad.gz 43f6cdce067f6794ec378c4e2a /sp/dir/su5/89/adf.gz 2f6c584116c567b0f26dfc8703 /sp/dir/su6/895/895.gz a864b7...

sc_trans metadataPattern

metadataPattern The pattern used to extract metadata from a file name if metadata does not exist or useMetadata == 0. default is /%N. for unix and \%N. for windows %N = song name %G = genre %A = album %R = artist %Y = four digit year %# = sequence of digits %% = % character [] = brackets option...

How important is adding quiet/verbose flags to new unix tools?

I'm writing some unix-style Ruby scripts that take option flags. Normally, I write a lot of STDOUT.puts and STDERR.puts statments in these scripts. Now I'm wondering whether it's "good form" to put in --verbose or -q flags for switching on or off helpful output to STDERR. Two arguments against doing that are that it would make the p...

BIND ERROR : Address already in use

I am learning socket programming in c, I wrote this simple program to accept connections on port 5072. i connect to it using telnet. This works fine the first time but when i try to run it again immediately it fails showing BIND : Address already in use, but then again starts to work after a minute or so. What am i doing wromg? #includ...

Concatenating file with path to get full path in C

Using C, I'm trying to concatenate the filenames in a directory with their paths so that I can call stat() for each, but when I try to do using strcat inside the loop it concatenates the previous filename with the next. It's modifying argv[1] during the loop, but I haven't worked with C in a long time, so I'm very confused... #include <...

Resources to learn C and its development tools for Unix

I know a little bit of C from high school and uni (mostly forgotten). I would like to learn C for Unix developemnt. I have a book of Dietel but there is not any information on how to use make, configure, Makefile and Posix API. I would like to have some resources, books, web sites, PDF, anything, to get started. I want to use gnu tools....

Using readv(), writev() and poll() from C++

There is a multiplayer card game which I had first programmed as a non-forking socket server in C (using poll() call). Then it was too difficult for me to add new features and I've switched to Perl (using IO::Poll module). As Perl doesn't support readv()/writev(), requires more memory/CPU and also isn't very commercial (I'd like to sel...

fork in a for loop

Hi, I have a doubt in the following piece of code and its behaviour: #include <stdio.h> #include <unistd.h> #include <stdlib.h> #define N 5 #define nt 1 int pm[N][2],pid[N]; int i,j,size; char s[100]; int count=0; int main() { for(i=1;i<N;i++) { printf("\n i=%d",i); if(pid[i]=fork() == -1) { print...

Bus error with semaphore func semctl() in this code running on Solaris

Hi everyone: This is my first attempt on semaphores and threads. I constructed this code from examples and the man pages found on the Net. I have two doubts with this code. Why do I get a Bus error whenever I try semctl( I know this is the root of the problem because of the debug line 3 does not get printed) and how to prevent it? Wh...