bash

Calling bash with PHP's shell_exec -- slow.

Hi, I'm using PHP's shell_exec function to call a bash script on my server. shell_exec("bash -x /tesladata/isetools/0-extractbytickerforweb.bash $ticker $isedate > /t24alv2/iseoutput/$ticker-$isedate-$thistime.log &"); Now, I previously had the command running from a CGI script ("bash -x...") and it was much faster (instantaneous). N...

BASH: Assign '&' to variable NOT as string

I wanted to conditionally run a command as a background or foreground process, so I wrote something like this: test $some_var; bg_suffix=& long_command $bg_suffix it doesn't work because bg_suffix is always empty whether it's been assigned or not. But test $some_var; bg_suffix="&" long_command $bg_suffix doesn't work either becau...

/bin/sh invoked from make doesn't find command with unquoted dash-argument

I have a makefile to build some transducers using Xerox' finite state tools (xfst in this case), which I invoke in my makefile like so (except with a hard tab instead of spaces in the actual makefile, of course): latin.fst: nouns.fst verbs.fst xfst -f build/latin.fst.build On my laptop (a Mac with OS X 10.6.2) this works just fine...

How can I obtain unmodified command line arguments to "wrap" another command line tool?

I want to write a script foo which simply calls bar with the exact same arguments it was called with, using Bash or Perl. Now, a simply way to do this in perl would be #!/bin/perl my $args=join(' ', @ARGV); `bar $args`; However, the values in ARGV have already been processed by the shell, thus if I call foo "I wonder, \"does this...

linux script simple arithmetic code

So I'm just working on some simple arithmetic code. Here's what I got: echo "The number should be 2"; declare -i input added input= date +%w let added="input/2" echo "$added" when I run it the output is 4 0 I'm trying to just get 2. What the heck am I doing wrong? ...

How do I simplify bash's 'eval "$TIME $BIN_FILE $BIN_OPTS &> $LOG_FILE"' and keep it working?

I'm updating a bash script which serves as a program testing tool. Previously, I had this line in a script working perfectly ($BIN_FILE is set to a relative path to the binary being tested): $BIN_FILE $BIN_OPTS &> $LOG_FILE Then I've decided to add some "performance measurements": time $BIN_FILE $BIN_OPTS &> $LOG_FILE" This worked ...

ls command: how can I get a recursive full-path listing, one line per file?

How can I get ls to spit out a flat list of recursive one-per-line paths? For example, I just want a flat listing of files with their full paths: /home/dreftymac/. /home/dreftymac/foo.txt /home/dreftymac/bar.txt /home/dreftymac/stackoverflow /home/dreftymac/stackoverflow/alpha.txt /home/dreftymac/stackoverflow/bravo.txt /home/dreftymac...

text manipulation and removal

I have text files generated by one of my tools with structure shown below. 1 line text (space) multiple lines text (space) multiple lines text nr 2 ---------------------------------------------------------- (58 '-' characters) different 1 line text (space) different multiple lines text (space) different multiple lines text nr 2 --------...

How can I make sure sox doesn't perform automatic dithering without knowing the version?

I'm using sox to resample audio before introducing it to our speech detection system, but I've hit a snag with version 14.3 of sox adding automatic dithering by default to the resampling operation, which we don't want. This wouldn't be a problem if we knew that we were always using sox 14.3, as we could just use the new -D flag to disa...

Recommendation - Zsh vs FishShell. Scripting, productivity and poweruser perse.

I have spent sometime trying to pick one, on net comparisons are for zsh vs bash and fish vs bash. But, I Could not find any comparison for zsh vs fish. I program in c/c++, apart from hello-world types, never done any major scripting. But now trying my hands at python and shell-scripts. Which shell keeps more juice in terms of productivi...

bash script for searching from a list of files in directory

There are around 20 files in a directory . Each file has the string $str inside it. I want to write a script that picks out that row containing the string $str and dump into a file . Each file should dump the searched row into a different file . For example file1 dumps searched row to file called found1 and file2 dumps it to file cal...

bash script to watch a folder

I have the following situation: There is a windows folder that has been mounted on a Linux machine. There could be multiple folders (setup before hand) in this windows mount. I have to do something (preferably a script to start with) to watch these folders. These are the steps: Watch for any incoming file(s). Make sure they are transfe...

How to iterate over positional parameters in a Bash script?

Where am I going wrong? I have some files as follows: filename_tau.txt filename_xhpl.txt fiename_fft.txt filename_PMB_MPI.txt filename_mpi_tile_io.txt I pass tau, xhpl, fft, mpi_tile_io and PMB_MPI as positional parameters to script as follows: ./script.sh tau xhpl mpi_tile_io fft PMB_MPI I want grep to search inside a loop, first...

Using DOS file contents as command line arguments in BASH...

This is a follow-up to this question's answer. How can I modify the code so that the annoying CRLF of a DOS created file can be stripped away before being passed to xargs? Example file 'arglist.dos'. # cat > arglist.unix src/file1 dst/file1 src/file2 dst/file2 src/file3 dst/file3 ^c # sed 's/$/\r/' arglist.unix > arglist.dos The uni...

mingw + python eagerly translating path

I am using: Windows XP Python 2.6.2 (standard install from python.org) git version 1.6.5.1-preview20091022 (installed from http://code.google.com/p/msysgit/) I have an environment variable looking like an absolute path (/path/to/dir) but I'm using it to construct a git URL. At some point, it's getting translated to C:/Program Files/G...

help with selecting rows using awk

I have a file as follows 2.54 Ghz val 2.53 Ghz val1 1.6 Ghz val2 800 Mhz val3 2.54 Ghz val4 2.53 Ghz val5 1.6 Ghz val6 800 Mhz val7 and the pattern continues ... I want to extract all 2.54 Ghz values in one file1 and all 2.53 Ghz values in another file2 , 1.60 Ghz values in file3 and 800 Mhz values in file4 ...

Bash: For Filename do......

Hi I'm not used to do things in Bash, so I'm having some problems: My goal is to look for special files in a folder, and if found generate some other files with the same filenames, but different extension. Something like: For Files-that-are-called-"SysBackup*.Now" do NewFileName = ChangeFileExt(FoundFilename),BK GenerateNewfile(N...

Filter lines by pattern in bash script

Hello! I have two variables, one with text, and another with patterns. And I want to filter out lines, matched patterns. How can I do that? My script looks like this # get ignore files list IGNORE=`cat ignore.txt` # get changed files list CHANGED=`git diff --name-only $LAST_COMMIT HEAD` # remove files, that should be ignored from cha...

Which programming language has very short context-free Grammar in its formal specification?

What programming language has short and beautiful grammars (in EBNF)? Some languages are easer to be parsed. Some time ago I have created a simple VHDL parser, but it was very slow. Not because it is implemented completely in Python, but because VHDL grammar (in EBNF) is huge. The EBNF of Python is beautiful but it is not very short. I...

Replace a line in a text file

Hello I've a text file with a line default_color acolor and I want to replace this line with default_color anothercolor I don't know the first color and the second is contained in a variable. How can I do it in bash ? Thank you ...