From: Jeenu on
Hi,

I have a file (myfile) containing the following lines:

a = 1
b = 2
c = 3

now if I do:

cat myfile | while read LINE; do
let "$LINE"
done

AFAIK, I should get the environment variables a, b and c, but it these
variables don't get assigned at all. Could somebody please tell me why
this is happening? Or isn't this the right way to use the 'let' built-
in?

Thanks
Jeenu
From: Bill Marcum on
On 2008-04-18, Jeenu <jeenuv(a)gmail.com> wrote:
>
>
> Hi,
>
> I have a file (myfile) containing the following lines:
>
> a = 1
> b = 2
> c = 3
>
> now if I do:
>
> cat myfile | while read LINE; do
> let "$LINE"
> done
>
> AFAIK, I should get the environment variables a, b and c set to the
> values, but these variables don't get assigned at all. Could somebody
> please tell me why this is happening? Or isn't this the right way to
> use the 'let' built-in?
>
> Thanks
> Jeenu

You should not have spaces before or after the = sign. Also, which shell
are you using? In most shells, when you use a pipe, every process in the
pipeline is executed in a subshell. In ksh or zsh, the last process in
the pipeline is not a subshell.
From: Janis on
On 18 Apr., 07:35, Jeenu <jee...(a)gmail.com> wrote:
> Hi,
>
> I have a file (myfile) containing the following lines:
>
> a = 1
> b = 2
> c = 3
>
> now if I do:
>
> cat myfile | while read LINE; do
>     let "$LINE"
> done
>
> AFAIK, I should get the environment variables a, b and c, but it these
> variables don't get assigned at all.

Is there a difference in your (which one?) shell when doing...

while read LINE; do
let "$LINE"
done <myfile


Janis

> Could somebody please tell me why
> this is happening? Or isn't this the right way to use the 'let' built-
> in?
>
> Thanks
> Jeenu

From: Skye Shaw! on
On Apr 17, 10:35 pm, Jeenu <jee...(a)gmail.com> wrote:
> Hi,
>
> I have a file (myfile) containing the following lines:
>
> a = 1
> b = 2
> c = 3
>
> now if I do:
>
> cat myfile | while read LINE; do
>     let "$LINE"
> done
>
> AFAIK, I should get the environment variables a, b and c, but it these
> variables don't get assigned at all. Could somebody please tell me why
> this is happening? Or isn't this the right way to use the 'let' built-
> in?
>
> Thanks
> Jeenu

What are you trying to do?
let is for arithmetic evaluation, Do you mean set?

[sshaw(a)localhost ~]$ cat bs.sh
y=1
x=$y+23
echo $x
let x=$y+23
echo $x
a=1
echo $a
a = 1 #oops, extra spaces

[sshaw(a)localhost ~]$ bash bs.sh
1+23
24
1
bs.sh: line 8: a: command not found


For assignments to bee seen by other processes, you must export them
via export or set -a

-Skye
From: pk on
On Friday 18 April 2008 07:47, Jeenu wrote:

> Hi,
>
> I have a file (myfile) containing the following lines:
>
> a = 1
> b = 2
> c = 3
>
> now if I do:
>
> cat myfile | while read LINE; do
> let "$LINE"
> done
>
> AFAIK, I should get the environment variables a, b and c set to the
> values, but these variables don't get assigned at all. Could somebody
> please tell me why this is happening? Or isn't this the right way to
> use the 'let' built-in?

Try this:

$ eval $(tr -d ' ' < myfile)
$ echo "$a -- $b -- $c"
1 -- 2 -- 3

Remember to use eval only if you're 100% sure that what you're going to
execute is safe.

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.