bash

How to verify information using standard linux/unix filters?

I have the following data in a Tab delimited file: _ DATA _ Col1 Col2 Col3 Col4 Col5 blah1 blah2 blah3 4 someotherText blahA blahZ blahJ 2 someotherText1 blahB blahT blahT 7 someotherText2 blahC blahQ blahL 10 someotherText3 I want to make sure that the data in 4th ...

bash trap of TERM - what am I doing wrong?

Given this hack.c program: #include <stdio.h> main() { int i=0; for(i=0; i<100; i++) { printf("%d\n", i); sleep(5); } } and this hack.sh bash script: #!/bin/bash ./hack If I run hack.sh, two processes get created - one for bash, one for the C task. If a TERM signal gets sent to the bash process, the C process is unharmed....

Bash: Join elements of an array?

If I've got an array like this in Bash: FOO=( a b c ) How do I join the elements with commas? For example, producing a,b,c. ...

SVN: "Inconsistent line ending style" - Checking in a file with ^M intentionally.

Using svn version 1.3.1 (unable to upgrade due to a configuration controlled CM server) on CentOS 4.2. My code (a bash script) specifically has a ^M in it for an important reason. Unfortunately, subversion will not let me check this file in. It complains that: svn: Commit failed (details follow): svn: Inconsistent line ending style svn...

Linux: GNU sort does not sort seq

Title sums it up. $ echo `seq 0 10` `seq 5 15` | sort -n 0 1 2 3 4 5 6 7 8 9 10 5 6 7 8 9 10 11 12 13 14 15 Why doesn't this work? Even if I don't use seq: echo '0 1 2 3 4 5 6 7 8 9 10 5 6 7 8 9 10 11 12 13 14 15' | sort -n 0 1 2 3 4 5 6 7 8 9 10 5 6 7 8 9 10 11 12 13 14 15 And even ditching echo directly: $ echo '0 1 2 3 4 5 6...

Tcsh and/or bash directory completion with variable hidden root prefix

I'm trying to set up directory completion in tcsh and/or bash (both are used at my site) with a slight twist: for a particular command "foo", I'd like to have completion use a custom function to match the first /-delimited term to an actual subtree node, and then follow normal directory completion for any successive terms. It is sort of...

can Bash be configured to search string on the current input line?

For fast locating positions when using the command line(Yes, I'm an Emacs fan). After viewing Bash' man, I can't find such tips. Does it need to modify readline's source code to support this? Thank you very much!! ...

Can't read variable that was stored from within a while loop, when out of the while loop.

I can't for the life of me see why I can not read the postPrioity outside the while loop. I tried "export postPrioity="500"" still didn't work. Any ideas? -- or in plan text -- #!/bin/bash cat "/files.txt" | while read namesInFile; do postPrioity="500" #This one shows the "$postPrioity" varible, as '500' echo "weeeeeeeeee --...

linux: copy and create destination dir if it does not exist

Linux: I want a command (or probably an option to cp) that creates the destination directory if it does not exist. Example: cp -? file /path/to/copy/file/to/is/very/deep/there ...

Monitor the data in a table

How to write a shell script/process which runs like a daemon on Unix and continuously monitors a field in the table and sleeps for 30 sec's. The field value will regularly increase to a maximum value and my process/script which is monitoring will provide a simple select query output to a log file. any approach is preferred. ...

De-dupe files in BASH

I have a set of, oh 8000 or so files, that I need to de-dupe. The files are essentially lists of numbers delimited by returns: nnnn nnnnn nnnn and I would like to sort and de-dupe the numbers within the files themselves. I can do this manually using sort | uniq or sort -u but I effectively want to overwrite the files. Is there a way ...

How would one implement bash-like tab completion?

I'm trying to determine how the system prints characters to standard input -- that is, how it prints characters which the user can delete and which are considered input if the user hits "Enter." I happen to be using C, but I would be very surprised if the solution were language-dependent. Thanks for any insights! : D ...

Printing out names of only directories and not files (BASH)

I have most of what I need so far I'm just unsure of the grep command to get only directories or if there isn't one. For context, this is the original request: This script should take a single command line argument which will be a path to a directory. (done) The script should make sure that the path is, in fact, a directory and that th...

How can I apply Unix's / Sed's / Perl's transliterate (tr) to only a specific column?

I have program output that looks like this (tab delim): $ ./mycode somefile 0000000000000000000000000000000000 238671 0000000000000000000000000000000001 0 0000000000000000000000000000000002 0 0000000000000000000000000000000003 0 0000000000000000000000000000000010 0 000000000000000000...

How to properly make path handling robust in a bash program?

The script have some hard-coded relative paths. I would like them to be relative to script position. The script needs to change current directory as some other program (cmake) needs it. The script takes some (possibly relative to caller) paths as an argument and it passes them to that program, they should be derelativized. Questions a...

csh list of commands like ksh { list; }

Hi, In bourne-compatible shells, the { list; } syntax causes the complete list of commands to be read by the shell before executing it, without opening a new shell. Is there anything similar for the csh? Thanks. ...

How can grep interpret literally a string that contains an asterisk and is fed to grep through a variable?

I have this script: #!/bin/bash CLASSPATH="/blah/libs/*:/blah/more/libs" CMD="java -cp $CLASSPATH MainClass" ALREADY_RUNNING_PID=`ps -ef --no-headers | grep $CMD | grep -v grep | awk '{print $2}'` if [ "$ALREADY_RUNNING_PID" ]; then echo "Already running" exit 1 fi $CMD & problem is it doesnt work due to the asterisk in th...

How do I forward parameters to other command in bash script?

Inside my bash script, I would like to parse zero, one or two parameters (script can recognize them). Then forward rest of parameters to a command invoked in the script. How to do it? ...

Bash: limit the number of concurrent jobs?

Is there an easy way to limit the number of concurrent jobs in bash? By that I mean making the & block when there are more then n concurrent jobs running in the background. I know I can implement this with ps | grep -style tricks, but is there an easier way? ...

Using conditional statements inside 'expect'

I need to automate logging into a TELNET session using expect, but I need to take care of multiple passwords for the same username. Here's the flow I need to create: Open TELNET session to an IP Send user-name Send password Wrong password? Send the same user-name again, then a different password Should have successfully logged-in at t...