LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.

Notices


Reply
  Search this Thread
Old 03-05-2006, 01:23 AM   #1
nikhil_rs_maheshwari
LQ Newbie
 
Registered: Feb 2006
Posts: 11
Blog Entries: 1

Rep: Reputation: 0
why do we use gerp & env & wht is their funda


hi

for instance i generally issue commands like

"ps -eaf|grep pmon" to identify process id as told by my friend but i don't konw wide application of grep & where else we can use it.

In shor i want to understand basic functionality of such commands & like wise -env & so on

plz help.

thanx well in advance.

regs
Nikhil
 
Old 03-05-2006, 01:37 AM   #2
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
check the grep man/texinfo page - on your computer or online.
(man grep or info grep)

ps -eaf produces screeds of output (try it) to stdout. What grep does is search through this output for any line which include a stated string - and displaying that. In this case, only lines containing the letters "mnon" will be displayed.

The use you have shown is the most common way of using grep - as an output filter.

Another example:

ls -l will list the long version of all files in a directory. Some directories contain 100s of files. If you just want to see the jpeg images (if any) you would do: "ls -l | grep jpg". And you can make a list of them with "ls -l | grep jpj > jpglist.txt"

But grep is used whenever you want to sort text. Like if you want to know how many times the word "the" appears in Moby Dick... or if you have accidentally deleted a file.

In general - if you want to know what a command does in a broader sence, google "man <command name>" and you'll get the technical description.
 
Old 03-05-2006, 01:42 AM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
I use grep mostly to find out which file(s) contain some certain thing. Like which source file contains a particular variable or function. Really, the uses are so diverse it would be impossible to make any sort of comprehensive list. I will say, though, that if you get yourself acquainted with the Unix standard notation for regular expressions, you will probably understand a lot better how grep was intended to be used.

As for 'env', I never even heard of it until I read your post. I usually use either 'set' or 'export' to do what 'env' seems to do. I doubt many people use this much.

--- rod.
 
Old 03-05-2006, 02:03 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by theNbomr
As for 'env', I never even heard of it until I read your post. I usually use either 'set' or 'export' to do what 'env' seems to do. I doubt many people use this much.

--- rod.
env is portable way to set and export a variable for a single command. It is simpler than the set / export builtins, and doesn't need a shell to be processed.
 
Old 03-05-2006, 02:20 AM   #5
nikhil_rs_maheshwari
LQ Newbie
 
Registered: Feb 2006
Posts: 11

Original Poster
Blog Entries: 1

Rep: Reputation: 0
thanx simon, for giving me detailed description of -eaf & use of grep for sorting purpose.

but one more option "env" is still not clear to me.

plz help me.
 
Old 03-05-2006, 05:39 AM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by nikhil_rs_maheshwari
but one more option "env" is still not clear to me.
Code:
env a=b command
is equivalent and simpler than

Code:
(
a=b
export a
command
)
 
Old 03-05-2006, 12:44 PM   #7
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Quote:
is equivalent and simpler than

Code:

(
a=b
export a
command
)
You are correct, but you could also have said
Code:
(export a=b; command)
which isn't really a lot more wordy than the equivalent 'env' method. I know I'm picking gnits.

--- rod.
 
Old 03-05-2006, 02:17 PM   #8
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by theNbomr
You are correct, but you could also have said
Code:
(export a=b; command)
which isn't really a lot more wordy than the equivalent 'env' method. I know I'm picking gnits.

--- rod.
You are right, and this command can even be made shorter with:
Code:
a=b command
The env point is that it needs not a specific shell to be understood. For example, not your example nor my last up here are correct with the bourne shell (the real one) or with csh.

In fact env doesn't even need a shell so you can call it directly from a C program with one of the exec family calls.

As a real life example, I'm using it in custom icewm menu entries to set the locale or the ld library path to specific values.
 
Old 03-05-2006, 02:22 PM   #9
technopark02
Member
 
Registered: Feb 2005
Distribution: Solaris 8 - 11, JDS Linux 3.0
Posts: 99

Rep: Reputation: 15
Quote:
[...] but you could also have said
Code:
(export a=b; command)
which isn't really a lot more wordy than the equivalent 'env' method. [...].
If you define the environment variable in a shell, it affects all commands/executables you run, until you unset the env variable.

On the other hand, using "env a=b command", affects only "command", but nothing else.

The following example, makes it clear:

% env LD_DEBUG=files date
10356:
10356: hardware capabilities - 0x1c6f [ SSE2 SSE FXSR MMX CMOV SEP CX8 TSC FPU ]
10356:
10356:
10356: configuration file=/var/ld/ld.config: unable to process file
10356:
10356:
10356: file=/lib/ld.so.1 [ ELF ]
10356: dynamic: 0xd27fbb18 base: 0xd27c8000
10356: envp: 0x8046fc0 auxv: 0x804708c
...
...
10356: 1: transferring control: /usr/bin/date
10356: 1:
Sun Mar 5 11:59:15 PST 2006
10356: 1:

% date
Sun Mar 5 11:59:18 PST 2006

Observe that there is no verbose output of run-time linker's activity, when the "date" command was executed for the 2nd time.

Just for fun:
set the same env variable (LD_DEBUG=files) in a shell using "setenv" or "export", and run some commands.
 
Old 03-06-2006, 09:01 AM   #10
AbrahamJose
Member
 
Registered: Feb 2006
Location: India
Posts: 167

Rep: Reputation: 31
Post Done

Yes technopark02
I have done it.
Now I am under total confusion.
 
Old 03-06-2006, 11:25 AM   #11
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Now I am under total confusion.
Try
Code:
LD_DEBUG=args,audit,basic,bindings,cap,detail,demangle,entry,files,got,init,libs,long,map,move,reloc,sections,segments,statistics,strtab,support,symbols,tls,unused,versions
for even more confusion ...

and
Code:
LD_DEBUG=
To reverse to a quiet behaviour.
 
Old 03-06-2006, 01:48 PM   #12
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Quote:
Originally Posted by technopark02
If you define the environment variable in a shell, it affects all commands/executables you run, until you unset the env variable.

On the other hand, using "env a=b command", affects only "command", but nothing else.
Actually, in bash, which seems to be the shell used by most linux users, environment variables are not passed on to child processes, unless they are exported. To use your example, try

Code:
(LD_DEBUG=files; date)

vs.

(export LD_DEBUG=files; date)
Again, I know I'm picking nits, here, and this is more of a 'bash-ism' than an 'env' thing.

The point about 'env' being independent of any particular shell is a good one.

--- rod.
 
Old 03-06-2006, 02:21 PM   #13
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by theNbomr
Actually, in bash, which seems to be the shell used by most linux users,
But this is a non Linux Forum, Solaris precisely, where the shell of choice is more ksh, although bash is a good contender, especially amongst beginners.
Quote:
environment variables are not passed on to child processes, unless they are exported.
This is true for all shells, although you can set an option to have variables exported by default.
Quote:
To use your example, try

Code:
(LD_DEBUG=files; date)

vs.

(export LD_DEBUG=files; date)
You seem to miss that the latter is equivalent to
Code:
(LD_DEBUG=files date)
which itself is launching a subshell for no reason, so can be itself simplified to
Code:
LD_DEBUG=files date
Making the "env" command useless when running a modern shell (ksh, bash, ...)
Quote:
Again, I know I'm picking nits, here, and this is more of a 'bash-ism' than an 'env' thing.
It is not a bash-ism, all bourne shells descendant and clones are behaving that way.
Quote:
The point about 'env' being independent of any particular shell is a good one.

--- rod.
env is not only independant of a shell, but in fact can live without a shell, something other variable assignement techniques rely on.

Last edited by jlliagre; 03-06-2006 at 02:23 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
zsnes && logitech dual action gamepad && dpad woes John5788 Linux - Games 5 10-29-2008 09:56 PM
AOL UK && BT Voyager 100 && Slackware 10.2 && RP-PPPoE pitt0071 Linux - Networking 3 01-17-2006 06:10 AM
Japanese canna won't work : Warning: &#12363;&#12394;&#28450;&#23383;&#22793;&am OrganicOrange84 Debian 3 06-30-2005 02:28 PM
Ph&#7909;c h&#7891;i d&#7919; li&#7879;u b&#7883; m&#7845;t???, c&#7913; pollsite General 1 06-27-2005 12:39 PM
bash env vars alias's & .bashrc micxz Linux - General 8 10-08-2003 02:09 PM

LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris

All times are GMT -5. The time now is 03:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration