bourne

How do I compare strings in Bourne Shell?

I need to compare strings in shell: var1="mtu eth0" if [ "$var1" == "mtu *" ] then # do something fi But obviously the "*" doesn't work in Shell. Is there a way to do it? ...

Compiling and Running java in Unix ( coming from Windows )

Ok, this is working on windows. My Java app is running and functioning normally javac -classpath .;ojdbc14.jar -g foo.java java -classpath .;ojdbc14.jar foo However, when I do the same thing on Unix I get this error: ojdbc14.jar: not found What am I doing wrong? I know the ";" is telling my shell that ojdbc14.jar is a new comma...

For Loop in Shell Script - add breakline in csv file

Hello all, I wish to introduce a for loop in my shell script and I was hoping I could get some help with this. I am executing a command from a text file. I wish to execute each command 10 times and insert some stats into a csv file. After that command has been done, I want to start the next BUT put a line break in the CSV file after th...

How do I capture the output of a command to a file descriptor in Bourne shell?

The standard way to capture command output in Bourne shell is to use the $() syntax: output=$(mycommand) For commands that have a lot of output, however, this requires the shell allocate memory for the whole thing as one long string. I'd prefer to find something that does the moral equivalent of the Unix C function popen, to get a new...

Running the rpmbuild command with the --quiet option flag results in extensive debug info.

Hi all, I wish to minimize the output of my rpm build procedure. I run the following command: rpmbuild -ba --quiet "/tmp/yaneeve/kit/linux/rpm_spec" My system is: Linux yaneeve-lnx-82-5 2.4.21-47.ELsmp #1 SMP Wed Jul 5 20:38:41 EDT 2006 i686 i686 i386 GNU/Linux The rpmbuild version is: RPM version 4.2.3 The %prep section of my rpm s...

Shellwords.shellescape implementation for Ruby 1.8

While the build of 1.8.7 I have seems to have a backported version of Shellwords::shellescape, I know that method is a 1.9 feature and definitely isn't supported in earlier versions of 1.8. Does anyone know where I can find, either in Gem form or just as a snippet, a robust standalone implementation of Bourne-shell command escaping for ...

Naming: BEGIN ~ END vs LIVE ~ EVIL block structured languages

Curly Bracket languages are well known: (wikipedia) Other programming languages can have BEGIN ~ END vs LIVE ~ EVIL block structuring. eg A) BEGIN ~ END, DO ~ END, IF ~ END IF - examples: Ada, Modula, Pascal, PL/I, Ruby etc... B) IF ~ FI, DO ~ OD, CASE ~ IN ~ OUT ~ ESAC - examples: Action!, ALGOL 68, Bourne shell, Co...

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

...

shell matching a pattern using a case-statement which is stored inside a variable

I am trying to match a pattern with a case-statement where the pattern is stored inside a variable. Here is a minimal example: PATTERN="foo|bar|baz|bla" case "foo" in ${PATTERN}) printf "matched\n" ;; *) printf "no match\n" ;; esac Unfortunately the "|" seems to be escaped (interestingly "*" or...

Is there a way to capture the output of a command, and its return value into variables in a shell script?

So, let's say that I have a command, foo, in a script which has both a return value, and an output string that I'm interested in, and I want to store those into a variable (well at least its output for the variable, and its return value could be used for a conditional). For example: a=$(`foo`) # this stores the output of "foo" if foo...

Bourne Shell Scripting -- simple for loop syntax

I'm not entirely new to programming, but I'm not exactly experienced. I want to write small shell script for practice. Here's what I have so far: #!/bin/sh name=$0 links=$3 owner=$4 if [ $# -ne 1 ] then echo "Usage: $0 <directory>" exit 1 fi if [ ! -e $1 ] then echo "$1 not found" exit 1 elif [ -d $1 ]...

bourne shell single-quote, doublequote & backquote question

Hi all, #/!bin/sh if [ "`echo $desc $status | awk -F"," '{print $3}' | awk -F" " '{print $1}' | sed '/^$/d'`" != "OK" ]; then echo "howdy dody" fi echo $desc $status | awk -F"," '{print $3}' | awk -F" " '{print $1}' | sed '/^$/d' First if-condition won't run, im guessing it's because of improper quotation, but i can't ...

Extracting a string from a file name

My script takes a file name in the form R#TYPE.TXT (# is a number and TYPE is two or three characters). I want my script to give me TYPE. What should I do to get it? Guess I need to use awk and sed. I'm using /bin/sh (which is a requirement) ...

How can I tell if a file is older than 30 minutes from /bin/sh?

How do I write a script to determine if a file is older than 30 minutes in /bin/sh? Unfortunately does not stat exist in the system. It is an old Unix system, http://en.wikipedia.org/wiki/Interactive_Unix Perl is unfortunately not installed on the system and the customer does not want to install it, and nothing else either. ...

Bourne Shell For i in (seq)

I want to write a loop in bourne shell which iterates a specific set of numbers. Normally I would use seq for i in `seq 1 10 15 20` #do stuff loop But seemingly on this Solaris box seq does not exist. Can anyone help by providing another solution to iterating a list of numbers? Thanks, Chris ...

Remove line breaks in Bourne Shell from variable

In bourne shell I have the following: VALUES=`some command that returns multiple line values` echo $VALUES Looks like: "ONE" "TWO" "THREE" "FOUR" I would like it to look like: "ONE" "TWO" "THREE" "FOUR" Can anyone help? ...

Why does this if statement fail in bourne shell?

I'm learning shell scripting but I can't work out this error, any help much appreciated. #!/bin/sh LOCATION=/tmp/loc PROXY=http://wwwproxy.unimelb.edu.au:8000 http_proxy=$PROXY; export http_proxy echo "Installing into" $LOCATION if [ ! -d $LOCATION ]; then mkdir $LOCATION; fi if [ ! -d $LOCATION/packages ]; then mkdir $LOCATION/packag...

Passing Bourne Shell var into cut command

I am trying to do the following. foo="foo:foo1" cc= `$foo | cut -f2 -d:` I understand why this would not work but I am at a loss as to do this. Thanks in advance. ...

Bourne Shell Left Right Justify

I am trying to do some formatting on output data in a script and not positive how to do Left Right justify as well as width. Can anyone point me in the right direction? ...

Bourne Shell exit will not work

Hi, I have the following script cat $1 | while read line do line=`echo $line | tr "[:lower:]" "[:upper:]"` if [ "`echo $line | cut -f1 -d:`" = "foo" ] && \ [ "`echo $line | cut -f2 -d:`" = "bar" ]; then echo 'exsist' exit 1; fi done everything works up to echo and then when the script hits exit it ...