bash

Bash, Serial I/O and Arduino

So, I'm in a bit over my head, and I feel like I'm very close to a solution but it's just not working quite yet. Here's my situation: I'm working with an Arduino MicroController, and I'm attempting to write two Bash scripts (right now running in MacOS 10.6) which will (a) print all serial data coming out of the Arduino unit to the stand...

How can I automatically open a file if it's the only result in grep?

[meder@kat directoryName]$ grep -RlI "send you instr" * application/views/scripts/auth/forgot.phtml [meder@kat directoryName]$ Is there a quick hack to referencing the only result? Can I somehow pipe it to vim? ...

How to parse $QUERY_STRING from a bash CGI script.

I have a bash script that is being used in a CGI. The CGI sets the $QUERY_STRING environment variable by reading everything after the ? in the URL. For example, http://example.com?a=123&b=456&c=ok sets QUERY_STRING=a=123&b=456&c=ok. Somewhere I found the following ugliness: b=$(echo "$QUERY_STRING" | sed -n 's/^.*b=\([^&]*\)....

Dumping text files

I'm writing a shell script that will create a textual (i.e. diffable) dump of an archive. I'd like to detect whether or not each file is printable in some given character set, and if it is printable, I'd like to convert to that character set from whatever one it's in, if this is possible, and make its contents part of the dump. I've co...

Linux shell passing variable values to main programme

I have a programme, ./a that I run in a loop in shell. for((i=1 ; i<=30; i++)); do ./a arg1 5+i &//arg2 that I need to pass in which is the addition with the loop variables done How could I passed in the arg2 which is the addition with loop variables? Also, I has another programme which is ./b which I need to run once and takes in a...

Pipeline metacharacter in variable in bash

In my bash script I need to check if logger binary exists. If so, I pipe the application output to it. Edit-------- | It needs to be piping, the application should work permanently. --------------- I tried to put the pipeline stuff to a variable and use it later. Something like: if [ -e /usr/bin/logger ]; then OUT=| /usr/bin/logger ...

How to echo a variable containing an unescaped dollar sign in bash

If I have a variable containing an unescaped dollar sign, is there any way I can echo the entire contents of the variable? For example something calls a script: ./script.sh "test1$test2" and then if I want to use the parameter it gets "truncated" like so: echo ${1} test1 Of course single-quoting the varaible name doesn't help. I ca...

how the keyword “if” test the value true of false?

In bash script if [ 1 ] then echo "Yes" else echo "No" fi Output: Yes It represent that '1' is treated as true value. But in code: word = Linux letter= nuxi if echo "$word" | grep -q "$letter" then echo "Yes" else echo "No" fi Output:No But echo "$word" | grep -q "$letter" will return 1, why the result is N...

Multiple cronjob emails

I have 3 jobs in my crontab. I want to recieve emails if only 1 of them fails and not for other two. Is there any way to restric emails to one type of cronjob? ...

Can You Embed an TCL Script in Bash Script or Python Script That's Callable by External Programs?

I'm writing a script to extract some useful data about a series of chemical simulations I've been running. To get this data I need (1) a C-program that calculates the density from a file type called *.pdb. I already have (1). And (2) I need to use a program called vmd to get that pdb. In order to accomplish (2) from the command line,...

In Bash, is there a way to "grep -r foobar *" except it is everything except the "log" directory?

the line \ls -1 | grep -v log | xargs grep -r foobar partially works except it will also skip the "blog" directory since it also gets excluded by grep -v log. (the \ls above is to make ls not do any alias such as ls -F) ...

RHEL 5 - Path Environment Variable Changes Don't Take Effect

Hello, I am having a problem in Red Hat Enterprise Linux, I'm a newb to Linux so this is probably something very simple. I installed a new 64-bit JDK (1.6.0_18) on RHEL 5 (64-bit), and now i need to set the path so that linux will go for the 1.6.0_18 instead of the old JRE 1.4.2. But everytime i set the path variable, its like the chang...

How can I make Bash automatically pipe the output of every command to something like tee?

I use some magic in $PROMPT_COMMAND to automatically save every command I run to a database: PROMPT_COMMAND='save_command "$(history 1)"' where save_command is a more complicated function. It would be nice to save also the head/tail of the output of each command, but I can't think of a reasonable way to do this, other than manually p...

Spaces in Cygwin/bash aliases?

I am attempting to set up aliases for my Cygwin bash shells, to run programs contained in the standard Windows C:\Program Files subdirectories. Unfortunately, the alias command really doesn't like spaces in a directory name, and nothing I've tried seems to work. I'm trying to get the following running: alias npp='/cygdrive/c/Program F...

Struggling to parse (bash) time command.

Hi there. I'm struggling to parse the output of the time command in bash - and even to stop it from printing out its output when I call it. This is my test code: #!/bin/bash TIME=`time ls -lh > /dev/null` echo "Testing..." echo $TIME This currently prints out: {blank-line} real 0m0.064s user 0m0.002s sys 0m0.005s Testing {b...

Version control for other kinds of files? (non-source code files)

Version control in programming is pretty much a necessity, and some programs allow for things like change-tracking or a form version control for files other than source code (like MS Word, InDesign, etc.). Is there any kind of system or architecture/protocol that could be put in place to establish version control for non-source code fil...

How to make files in Linux folder with default group write permission

I have the folder called backups. The root is putting backups in that folder. I want that all the files which are created in that folder should have group write permission. I know i can use umask but i want to know that will umask work for all the files any where or it will work on particular folder. e,g i want umask for only /backups ...

Remove file in a tar, with wildcard and exception

I have a tarball, and i want to remove all .tcl, .bat , .log files except pkgIndex.tcl in it. if i do tar --delete -f mytarball.tar --wildcards *{.tcl,.log,.bat} my pkgIndex.tcl will be deleted, how to put that as exception in my pattern wildcard? Just tried tar --delete -f mytarball.tar --wildcards *{.tcl,.log} --exclude=*pkgIn...

How to remove two lines from terminal output

Given that two lines have been printed out in the terminal, is it possible to delete both of them so they may be replaced with two new lines? I know you can use \r to replace 1 line (well, to move the cursor to the start of the line), but is there any way of doing this for the line above? As an example, I'm running a program for comput...

Trigger the UP key in command line?

Is there a way to trigger/fire the UP key in the command line? Instead of me having to press UP key. ...