sh

autoconf using sh, I need SHELL=BASH, how do I force autoconf to use bash?

I'm running autoconf and configure sets SHELL to '/bin/sh'. This creates huge problems. How to force SHELL to be '/bin/bash' for autoconf? I'm trying to get this running on osx, it's working on linux. Linux is using SHELL=/bin/bash. osx defaults to /bin/sh. ...

Using getopts within user-defined-function in bourne shell

Is it possible to pass command line arguments into a function from within a bourne script, in order to allow getopts to process them. The rest of my script is nicely packed into functions, but it's starting to look like I'll have to move the argument processing into the main logic. The following is how it's written now, but it doesn't ...

Iterating over two lists in parallel in /bin/sh

I have two lists of equal length, with no spaces in the individual items: list1="a b c" list2="1 2 3" I want to iterate over these two lists in parallel, pairing a with 1, b with 2, etc.: a 1 b 2 c 3 I'm attempting to support modern portable Bourne shell, so Bash/ksh arrays aren't available. Shelling out to awk would be acceptable ...

Select unique or distinct values from a list in UNIX shell script

I have a ksh script that returns a long list of values, newline separated, and I want to see only the unique/distinct values. It is possible to do this? For example, say my output is file suffixes in a directory: tar gz java gz java tar class class I want to see a list like: tar gz java class ...

BASH ^word^replacement^ on all matches?

To clarify, I am looking for a way to perform a global search and replace on the previous command used. ^word^replacement^ only seems to replace the first match. A quick check through a BASH history cheat sheet doesn't reveal anything. Is there some set option that is eluding me? Mainly curious... Thanks ...

Run CMD equivalent in OSX?

I'm using this code to make my Java program open a (visible) CMD window: try { String line; Process p = Runtime.getRuntime().exec("cmd /C start \"Render\" \"" + myPath + "\\punchRender.cmd\""); BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); ...

Write an executable .sh file with Java for OSX

So I am trying to write an .sh file that will be executable, this is how I'm currently writing it: Writer output = null; try { output = new BufferedWriter(new FileWriter(file2)); output.write(shellScriptContent); output.close(); } catch (IOException ex) { Logger.getLogger(PunchGUI.class.getName()).log(Level.SEVERE, null, ex); }...

How to do a script in BASH which takes random text from file?

I have file like: aaa bbb ccc ddd eee And I want to do a script in BASH which can takes random line of this text file, and return it to me as variable or something. I hear it can be done with some AWK. Any ideas? UPDATE: I now using this: shuf -n 1 text.txt Thanks you all for help! ...

How to get script file path inside script itself when called through sym link

Hi, When I need to get path to the script file inside script itself I use something like this: `dirname $0` that works file until I call the script through sym link to it. In that case above code prints the location of the link instead the original file. Is there a way to get the path of the original script file, not the link? Than...

sh read command eats slashes in input?

Perhaps easiest to explain with an example: $ echo '\&|' \&| $ echo '\&|' | while read in; do echo "$in"; done &| It seems that the "read" command is interpreting the slashes in the input as escapes and is removing them. I need to process a file line by line without changing its contents and I'm not sure how to stop read from being s...

manipulate parameters in sh

I'm working with a utility (unison, but that's not the point) that accepts parameters like: $ unison -path path1 -path path2 -path path3 I would like to write a sh script that I could run like this: $ myscript path1 path2 path3 I'm hoping for a Posix compliant solution, but bash-specific would also be good. I'm guessing it should ...

shell script to spawn processes, terminate children on SIGTERM

I want to write a shell script that spawns several long-running processes in the background, then hangs around. Upon receiving SIGTERM, I want all the subprocesses to terminate as well. Basically, I want a "master process". Here's what I got so far: #!/bin/sh sleep 600 & PID1="$!" sleep 600 & PID2="$!" # supposedly this should kill...

Separating objects and source with a makefile

Hi, I have been having troubles getting my makefiles to work the way I want. First off, I would like to say this is POSIX make, as in http://www.opengroup.org/onlinepubs/009695399/utilities/make.html I am needing my build system to work with both BSDs and GNUs(Linux). What I am wanting is a zero maintenance makefile. I want it to just c...

Shell scripting for godaddy coupon codes - how does this script work?

On a coupon site someone posted a shell script for finding Godaddy discount codes. 1 - Could someone explain how this script works? Specifically, I'm confused about the syntax: links url -dump | grep AI 2 - Does shell scripting allow you to spider a site just as perl/python/ruby would? 3 - Is the most efficient way to accomplish...

To make a if-clause in Sh

I have the following in a file which is sourced both by .bashrc and .zshrc. The syntax is from the site. if $SHELL=/bin/zsh then # to not java .class when running java myclasslist () { reply=(${$(ls *.class)%.class}) } compctl -K mycl...

Getting user input after stdin has been redirected, in a bourne script

...

running process in backround using a bash script

I want run a script as follows: runner: ssh 'java program &' ssh 'java program &' How do I write the script to fork the first process? Currently, it waits for it to finish. thanks ...

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

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

sh - Build string containing paths

I'm building a small shell script for finding cat/man pages on a wide range of unix systems... in bash, I could build all possible paths by doing this: # default search paths default=$(echo /usr/{share, local, dpkg, XR11}/man/{man, cat}{1..8}) for path in $default do ... done Unfortunately, I'm forced to use sh... I could build th...