LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 07-11-2006, 02:37 AM   #1
prospekrisal
LQ Newbie
 
Registered: May 2006
Location: Kuching, Malaysia
Posts: 26

Rep: Reputation: 15
Question shell command


hi guys, would you tell me what's wrong with these commands!!
1) fahrisal@linux:~> name=1
fahrisal@linux:~> $name
bash: 1: command not found

2)fahrisal@linux:~> name=Risal
fahrisal@linux:~> $name
bash: Risal: command not found

3)fahrisal@linux:~> name=Risal kadrie
bash: kadrie: command not found

What is an active process in the system? how to disply it?
 
Old 07-11-2006, 02:55 AM   #2
cdhgee
Member
 
Registered: Oct 2003
Location: St Paul, MN
Distribution: Fedora 8, Fedora 9
Posts: 513

Rep: Reputation: 30
To start with, you are trying to execute these variables rather than display them. What I think you want would be:

Code:
fahrisal@linux:~> name=1
fahrisal@linux:~> echo $name
There is an additional problem in number 3: Linux uses whitespace as delimiters between command-line options, so if you want to assign a string containing a space, you need to quote the string thus:

Code:
fahrisal@linux:~> name="Risal kadrie"
Then you should get the desired effect:

Code:
david@malvern:~ $ name=1

david@malvern:~ $ echo $name
1

david@malvern:~ $ name=Risal

david@malvern:~ $ echo $name
Risal

david@malvern:~ $ name="Risal kadrie"

david@malvern:~ $ echo $name
Risal kadrie
 
Old 07-11-2006, 02:55 AM   #3
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

Rep: Reputation: 56
Code:
[ sylvester :: cam ]-> name=1
[ sylvester :: cam ]-> echo $name
1
[ sylvester :: cam ]-> name="Cameron Daniel"
[ sylvester :: cam ]-> echo $name
Cameron Daniel
 
Old 07-11-2006, 02:56 AM   #4
prospekrisal
LQ Newbie
 
Registered: May 2006
Location: Kuching, Malaysia
Posts: 26

Original Poster
Rep: Reputation: 15
echo $name

name="Risal kadrie"
 
Old 07-11-2006, 02:56 AM   #5
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

Rep: Reputation: 56
Damn, beaten to the punch
 
Old 07-11-2006, 02:58 AM   #6
prospekrisal
LQ Newbie
 
Registered: May 2006
Location: Kuching, Malaysia
Posts: 26

Original Poster
Rep: Reputation: 15
What is an active process in the system? how to disply it?
 
Old 07-11-2006, 02:59 AM   #7
b0uncer
Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
Sure. First you did right,

name=1

should tell name equals to 1. After this you should use export like

Code:
export name
and after this you could see the variable, not by typing $name (which tells bash it's a program called $name) but using echo instead:

Code:
echo $name
The export is not necessary (at least in all situations) but might help.

EDIT: and I swear I just saw only three persons active on this thread..where did those other come from? Huh? And why haven't they *still* read my suggestion about an answer-lock of some kind to prevent a waste of posts like this..

Last edited by b0uncer; 07-11-2006 at 03:01 AM.
 
Old 07-11-2006, 03:01 AM   #8
cdhgee
Member
 
Registered: Oct 2003
Location: St Paul, MN
Distribution: Fedora 8, Fedora 9
Posts: 513

Rep: Reputation: 30
Quote:
Originally Posted by prospekrisal
What is an active process in the system? how to disply it?
An active process is just a program that is running. To display a list of all processes running, you can use this command:

Code:
ps -ef
You can then filter that down using grep to find exactly what you're looking for.
 
Old 07-11-2006, 03:04 AM   #9
cdhgee
Member
 
Registered: Oct 2003
Location: St Paul, MN
Distribution: Fedora 8, Fedora 9
Posts: 513

Rep: Reputation: 30
Quote:
Originally Posted by b0uncer
The export is not necessary (at least in all situations) but might help.
Correct - export is only necessary if you wish other programs to be able to access your variable. For example, if you are setting an environment variable that another program runs. If you don't export the variable, its scope is treated as being local to the shell/script (depending on where it's being set) - i.e. not part of the environment.
 
Old 07-11-2006, 03:04 AM   #10
b0uncer
Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
...and even use
Code:
ps aux
to get some more (possibly unneeded) information. Though that "aux" combination doesn't seem to work on every ps command I've encountered..

EDIT:
Quote:
Correct - export is only necessary if you wish other programs to be able to access your variable. For example, if you are setting an environment variable that another program runs. If you don't export the variable, its scope is treated as being local to the shell/script (depending on where it's being set) - i.e. not part of the environment.
Thanks - that's by far the best (compact) explanation for "export" I've heard.

Last edited by b0uncer; 07-11-2006 at 03:05 AM.
 
Old 07-11-2006, 03:24 AM   #11
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
I think the "export" command needs more explanation. When you start a program, it inherits the environment with variables defined such as $HOME. Your program, let's call it "parent", might define one or more variables. Defining a variable places it in local memory and not the environment. If you call another program in the "parent" program, let's call it child, the variables you set will not be defined in "child" unless you export them.

If you define a variable in child, even if you export it, it won't be seen in the parent after child finishes. This is because the child program runs in a subshell. What you could do is source the child program either like:
source child
or
. child

Now the child program is read in and executed in the same shell instead of a subshell, and the variable is defined.

Code:
cat parent
#!/bin/bash
echo $HOME

name=smith
echo $name
./child
echo $name

cat child
#!/bin/bash
echo $HOME
echo $name

./parent
/home/jsmith
smith
/home/jsmith

smith
The variable "name" wasn't defined in child, because "export name" wasn't run before calling child.
 
  


Reply

Tags
bash, scripting


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
a shell command RezaFiouji Programming 1 05-01-2006 04:27 AM
Shell Command rakriege Linux - General 1 10-04-2004 04:21 PM
Shell command (Try this out!!!!!!!) vbhatia_81 Programming 6 06-23-2004 02:43 AM
what is the shell command to.... praefex Linux - Newbie 2 08-18-2003 05:25 PM
QT --how to do a shell command linuxlah Programming 2 08-22-2002 02:27 PM


All times are GMT -5. The time now is 09:23 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration