Passing variable values to commands

Passing variable values to commands

Post by Holme » Mon, 31 Jan 2000 04:00:00



I know how to pass a variable value to awk in a bourne shell, for
example:

who | awk '/^'"$VALUE"'/ {print $2}'

How can I pass the $VALUE to grep without outputting it to a file and
grepping the file?

I've tried: grep foo "$VALUE"
but it crashes the script.

TIA

 
 
 

Passing variable values to commands

Post by Holme » Mon, 31 Jan 2000 04:00:00




> >How can I pass the $VALUE to grep without outputting it to a file and
> >grepping the file?
> Are you going to grep the string in $VALUE? If yes:
> echo $VALUE | grep WHAT

> --

> GC{S,M} d- s+:+ a18 C+++ UL++ L+++ E--- W
> P- N++ w-- O- t--- X+ b- DI+ e- h* r++ y?

That works great, silly me for overlooking the simple!
Thanks!

 
 
 

Passing variable values to commands

Post by Micha? Kuratcz » Tue, 01 Feb 2000 04:00:00



>How can I pass the $VALUE to grep without outputting it to a file and
>grepping the file?

Are you going to grep the string in $VALUE? If yes:
echo $VALUE | grep WHAT

--

GC{S,M} d- s+:+ a18 C+++ UL++ L+++ E--- W
P- N++ w-- O- t--- X+ b- DI+ e- h* r++ y?

 
 
 

Passing variable values to commands

Post by Benjamin Scot » Mon, 07 Feb 2000 04:00:00



> How can I pass the $VALUE to grep without outputting it to a file and
> grepping the file?

  I'm not exactly sure what you're trying to do.

  If you are trying to search for a match on "pattern" against a file whose
name is contained in $VALUE, then simply pass the variable on the command line
where the file name would usually go:

        grep pattern $VALUE

  If you are trying to search for a match on "pattern" against the contents of
the variable $VALUE, then use the "echo" command to output the variable to
stdout, and pipe that through grep:

        echo $VALUE | grep pattern

  Hope this helps!

--
Ben Scott

 Sent via Deja.com http://www.deja.com/
 Before you buy.

 
 
 

1. How do I pass variable values from a subprocess to parent shell process?

In particular in the public domain kshell:

commands of the form:
##################################

function x {
  # assign variables locally in here!

#now invoke x and see its variables as global from here
x <  afile

print varaibles assigned during execution of function x

##################################

When I attempt this scenario, I cannot see any of the values for variables
that have been assigned inside function x (execept when I am inside the
function itself).
The same problem holds true if I attempt to use the anonymous function
construct:
{ block of code } <  afile
I still cant see value of variables assigned in block of code.

Same again if I attempt to pipe values in:
ls | {
  block of code
I still cant see value of variables assigned in block of code.

I understand there is a problem with pdksh  of the form
print x | read a; print $a #This will not show value of $a.

Is this all related? I found a similar problem with bash.

Has anyone got a workaround to get values in/out between subprocess and
parent shells?

Hope this email is clear.
Hope someone can help, many thanks Nigel.

2. QWK-convert?

3. passing variable values

4. Strange 'ping localhost' results

5. how to pass variable into a function to have its value set

6. STLport 4.0 Beta snapshot 4 released

7. Passing system command value's

8. Config File for Compaq LTE5000?

9. How to enter values during pkgadd installation and pass those values to postinstall process?

10. Passing variables as arguments to commands in a shell script

11. passing a variable to the `date` command

12. Passing variables on the command line to a bash script

13. Assigning a variable a value with the "time" command