shell-scripting

Ant exec shell script - loses environment

I am trying to exec a shell script like so in ant: <exec executable="bash" newenvironment="false" dir="./"> <arg value="script.sh"> </exec> But when it executes the script, all references to environment variables such as $MY_VARIABLE come back as the empty string. How do I get around this? According to http://ant.apache.org/manual/C...

shell script printing contents of variable containing output of a command removes newline characters

I'm writing a shell script which will store the output of a command in a variable, process the output, and later echo the results. Here's what I've got: stuff=$(diff -u pens tape) # process the output echo $stuff The problem is, the output I get from running the script is this: --- pens 2009-09-27 10:29:06.000000000 -0400 +++ tape 20...

submitting multiple files from shell script through standard input

I have a program which reads from standard input when invoked from the command line. Normally the user would enter some information, press C-d on a new line to signal end of file, and the program would process the file. Then the user would again be prompted, would enter some more text, and again press C-d to signal the end of the second ...

Need to write a program to sanely configure a login shell

I just started using a Solaris 10 (Sparc) box where I telnet in and get confronted with a very unfriendly interface (compared to the standard bash shell I use in cygwin or linux) --- the arrow keys do not work as I expect them to. Being an NIS system, changing the shell is not as easy as using the "chsh" command. And setting the SHELL ...

GUI shell script editor with function overview

Is there an editor for Unix shell scripts such as Bash that has a kind of function overview as most Eclipse editors? I have a really large shell script with a lot of functions here and I want to move quickly from one function to next. Or is there any other way to get such an overview? ...

shell script to compare files and print formatted output

I'm trying to write a shell script which will compare two files, and if there are no differences between then, it will indicate that there was a success, and if there are differences, it will indicate that there was a failure, and print the results. Here's what I have so far: result = $(diff -u file1 file2) if [ $result = "" ]; then ...

Best method of triggering a shell script from Java

I have a shell script which I'd like to trigger from a J2EE web app. The script does lots of things - processing, FTPing, etc - it's a legacy thing. It takes a long time to run. I'm wondering what is the best approach to this. I want a user to be able to click on a link, trigger the script, and display a message to the user saying tha...

extract filename from path in csh shell -- from list of files

How to extract filename from the path; i have a list of files. I'm using csh shell, and have awk, sed, perl installed. /dfgfd/dfgdfg/filename should give me filename I tried basename: find $PROJDIR -name '*.c' -o -name '*.cc' -o -name '*.h' | xargs grep -l pattern | xargs basename and it gave me the following error: basen...

How do you call a function defined in .bashrc from the shell?

In my .bashrc, I have a function called hello: function hello() { echo "Hello, $1!" } I want to be able to invoke hello() from the shell as follows: $ hello Lloyd And get the output: > Hello, Lloyd! What's the trick? (The real function I have in mind is more complicated, of course.) EDIT: This is REALLY caused by a syntax e...

file empties itself

hello i have a shell script that sends out email. here is how it works: it reads the html from an url and put it in a file loop through all the emails and in the loop it reads from that html file the problem is: the html file becomes empty after a few hundred email for no apparent reason. (i put du /thehtml.html in the email log.)...

Shell script - kill self when app not running

I have my Cocoa app executing a shell script. I want to make it so that the shell script automatically kills itself if it finds that the host .app is not running. Right now what I have is the shell script polls using the UNIX "ps" command every time before it executes a command, and then kills itself if the app is not running. However th...

How to add timestamp to STDERR redirection

In bash/ksh can we add timestamp to STDERR redirection? E.g. myscript.sh 2> error.log I want to get a timestamp written on the log too. ...

How can I detect that emacs-server is running from a shell prompt?

I want to have my .bashrc detect if running emacsclient would work in lieu of running emacs. Basically: if emacs_server_is_running; then EDITOR=emacsclient VISUAL=emacsclient else EDITOR=emacs VISUAL=emacs fi What would I put in the emacs_server_is_running function to accomplish this aim? ...

Modified Copying

Is there anyway by i can copy files of a directory recursively by checking if the file already exist in the destination (specifically by using cksum command) during the copy procedure?? ...

Finding a pattern and extracting it into another file using sed in BASH

I have a few SQL scripts which contains table creation SQL statements. I want to remove all the statements having foreign key mappings. For example below is one script. CREATE TABLE x ( ORG_ID NUMBER primary key, BILLING_doc xmltype ); alter table x add (constraint fk_x foreign key (org_id) references organization\r (org...

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 --...

Special Character in Export Variable

I have a variable in my shell script that needs to declared as follows: MY_VAR="/path/to/exec -options < inputfile" This is the standard way the executable takes the input. Now, if I do $MY_VAR, the program quits with an error too many arguments. I suspect it is the < sign that is causing the problem. Any way I can get a workaround wi...

grep utility in shell script

I'm trying to overcome a limitation on our file structure. I want to grep a whole series of files in a known location. If I do a standard grep from command line (grep -i searchpattern known_dir/s*.sql) I get the following error: ksh: /usr/bin/grep: 0403-027 The parameter list is too long. so I have a little for loop that looks l...

How to use for loops in command prompt in csh shell -- looking for decent one liners

coming from bash shell, I missed on an easy rolling of loops (for i in (...); do ... done;) Would you post typical one-liners of loops in cshell? ONE LINERS PLEASE, and not multiple-lines thx ...

CURL fails to send post data over 1024 bytes via command line

I am trying to post a large XML file to a web address by using curl in a shell script. I am posting the data using the '-F' option in curl. Whenever I post a file larger than 1024 bytes, the file gets cut off and only sends the first 1024. I've tried changing the "Expect:" header as suggested in another solution for PHP Curl, but it d...