Subject: RE: bash questions
From: [email-masked] (Howarth, Richard)

9 Feb 1998 02:31:25 -0800
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: multipart/mixed;
	boundary="---- =_NextPart_000_01BD3543.8C4A9160"
To: [email-masked]

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------ =_NextPart_000_01BD3543.8C4A9160
Content-Type: text/plain

As has been stated elsewhere on the list, if you want to run csh scripts
get hold of a ported csh - it will save you a lot of grief.
If you really want to convert your scripts to run under bash though I
hope the following ideas will help ...

> ----------
> From: 	Eric Horowitz[SMTP:[email-masked]]
> Sent: 	06 February 1998 14:07
> To: 	[email-masked]
> Subject: 	bash questions
> 
> 
> I installed gnu-win32 simply to run some csh scripts that I had on a
> Solaris box. In the process of converting this script to bash I have
> encountered the following problems...
> 
> 1) set 
> 
>    It does not seem to do anything. I have been using declare instead.
> Is set
>    supposed to set variables?
Not really. It is used more for switching features of bash on and off,
although it can be used to set positional parameters (see later)
to set a parameter, simply assign it:
 $ PARAM="something or other"
If you need the parameter to be visible to sub-processes, export it:
 $ export PARAM 

> 2) let
> 
>       let THREE=1+2
> 
>    works fine in that 
> 
>       echo $THREE
> 
>    responds with 3, but...
> 
>       let OLTT=1<2
> 
>    responds with...
> 
>       2: no such file or directory
The problem is that the "<2" is being interpereted as redirecting input
from a file, named "2" in this case.
You can either wrap the expression in quotes, or use the "$(("
construction:
 $ let OLTT="1<2"
or
 $ OLTT=$((1<2))
both work.

> 3) If I have a string of items such as...
> 
>       declare ALIST="abc def ghi jkl mno pqr"
> 
>    I can access items individually in a for command such as...
> 
>       for ITEM in $ALIST; do
> 
>   but is there a command or syntax that will let me access any one
> specific
> member? I would
>   like to do something like...
> 
>       declare THIS_ITEM=$ALIST[$INDEX]
The korn shell has a "set -A" for simple arrays, but I can't find this
in bash.
You could try one of the following:
 $ ALIST="One Two Three Four"
 $ set $ALIST --
 $ THIS_ITEM=$3
 $ echo $3
 Three
or, using awk:
 $ ALIST="One Two Three Four"
 $ INDEX=2
 $ THIS_ITEM=$( echo $ALIST | awk -v INDEX=$INDEX "{print $INDEX}")
 $ echo $THIS_ITEM
 Two
NB these methods will allow you to retrieve specific subscript values,
they will not allow you to modify them.

> 4) test
> 
>    I would like to make complicated arithmetic relational operations
> such
> as...
> 
>    test ($V1 -lt $V2) -a ($V3 -lt $V4)
>    but I am not getting the syntax quite right. Is there a way to do
> this?
> 
I think you need to escape the parentheses, so that they are not
interpereted by the shell.
 $ test \( $V1 -lt $V2 \) -a \( $V3 -lt $V4 \)
seems to work.

NB while looking at these questions I noticed an odd thing:
 $ test 1 -lt 2
returns "0", but
 $ let "TEST=(1<2)"
results in TEST being assigned "1"

> Thanks... Eric Horowitz
My pleasure.
> -
> For help on using this list (especially unsubscribing), send a message
> to
> "[email-masked]" with one line of text: "help".
> 

------ =_NextPart_000_01BD3543.8C4A9160
Content-Type: application/ms-tnef
Content-Transfer-Encoding: base64

------ =_NextPart_000_01BD3543.8C4A9160--
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".