LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-26-2010, 06:49 PM   #1
Hi_This_is_Dev
Member
 
Registered: May 2009
Location: India
Distribution: On my PC I use RHEL, at office AIX, Solaris, HP-UX, RHEL.
Posts: 254

Rep: Reputation: 18
export is not working on command prompt


Hi,


The command export is working inside a shell script, but when I type it at the command prompt / terminal it doesn't work. "export: The command not found" error is displayed instead.

I tried this:

cat test.sh

Code:
abc=123
export abc
echo "Exit status of export abc: $?"
Code:
# bash test.sh
Exit status of export abc: 0
But when I type it at the command prompt:

Code:
# export abc=123
I get the "the command not found" error.

Code:
man export
is also working fine.

I tried it before on my RHEL system and it was working. I have checked
Code:
echo $PATH
which is okay. What could be the problem?
 
Old 08-26-2010, 09:24 PM   #2
carltm
Member
 
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 703

Rep: Reputation: 99
It could be that your shell is not of the Bourne Shell family.

What is the output of this command?

grep ^`echo $USER`: /etc/passwd
 
1 members found this post helpful.
Old 08-27-2010, 06:11 AM   #3
Hi_This_is_Dev
Member
 
Registered: May 2009
Location: India
Distribution: On my PC I use RHEL, at office AIX, Solaris, HP-UX, RHEL.
Posts: 254

Original Poster
Rep: Reputation: 18
Quote:
Originally Posted by carltm View Post
It could be that your shell is not of the Bourne Shell family.

What is the output of this command?

grep ^`echo $USER`: /etc/passwd
I will check that command. But the shell I am using is certainly bash as I have checked the file /etc/passwd several times.

In fact, I have run export on the command prompt before. But I am not sure what is wrong going on this time.
 
Old 08-27-2010, 06:19 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
What is the output of type export ?
 
1 members found this post helpful.
Old 08-27-2010, 07:20 AM   #5
Hi_This_is_Dev
Member
 
Registered: May 2009
Location: India
Distribution: On my PC I use RHEL, at office AIX, Solaris, HP-UX, RHEL.
Posts: 254

Original Poster
Rep: Reputation: 18
Quote:
Originally Posted by catkin View Post
What is the output of type export ?

I will post it after 9 hours. I am at office right now. The problem I observed is on my personal computer at my room.


But thanks for the useful command: type

I have checked this command on the system I am using righ tnow:

Code:
-bash-2.05b# type export
export is a shell builtin
-bash-2.05b# type ls
ls is aliased to `ls --color=tty'
-bash-2.05b# type dir
dir is hashed (/usr/bin/dir)
-bash-2.05b# type echo
echo is a shell builtin
-bash-2.05b# type :
: is a shell builtin
-bash-2.05b#

What does this output, as given above and below, mean?

Code:
-bash-2.05b# type dir
dir is hashed (/usr/bin/dir)
Specifically the term "hashed" used here...?
 
Old 08-28-2010, 12:49 PM   #6
Hi_This_is_Dev
Member
 
Registered: May 2009
Location: India
Distribution: On my PC I use RHEL, at office AIX, Solaris, HP-UX, RHEL.
Posts: 254

Original Poster
Rep: Reputation: 18
Thumbs up first where to check when a command is not working

Quote:
Originally Posted by carltm View Post
It could be that your shell is not of the Bourne Shell family.

What is the output of this command?

grep ^`echo $USER`: /etc/passwd
I have just found that my shell got changed to csh and it was creating the problem.

Code:
[root@localhost ~]# grep ^"$USER" /etc/passwd
root:x:0:0:root:/root:/bin/csh
I changed it to bash and the problem was resolved!


Code:
[root@localhost ~]# type export
export is a shell builtin
I experimented with these commands:

Code:
[root@localhost ~]# csh
[root@localhost ~]# type export
type: Command not found.
[root@localhost ~]# bash
[root@localhost ~]# type export
export is a shell builtin
[root@localhost ~]# grep ^"$USER" /etc/passwd
root:x:0:0:root:/root:/bin/bash

That is interesting. But I don't remember changing the shell. I had added two users before and just now I added one more:

Code:
[root@localhost ~]# tail -n 3 /etc/passwd
DEV:x:500:500:Dev's Account for Testing Purpose:/home/DEV:/bin/bash
Demo:x:501:502::/home/Demo:/bin/bash
test:x:502:503::/home/test:/bin/bash
and they all have bash as the default shell for their log-in sessions.


Anyways, the problem has taught me some troubleshooting techniques

Quote:
type <command> <enter>
and first where to check when a command is not working, i.e. the log-in shell.

Code:
grep ^"$USER" /etc/passwd
or

Code:
echo $SHELL

Thanks to all of you!

Last edited by Hi_This_is_Dev; 08-28-2010 at 12:52 PM.
 
Old 08-28-2010, 07:28 PM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by Hi_This_is_Dev View Post
What does this output, as given above and below, mean?

Code:
-bash-2.05b# type dir
dir is hashed (/usr/bin/dir)
When a command is not a bash alias, builtin or function, bash searches the directories listed in the value of the $PATH variable for a file that matches the command's name. This search is relatively "expensive" so, for better performance, bash keeps a table of commands that it has already looked up, known as a hash table, which it consults before scanning all the $PATH directories. There's more about it here if you scroll down to hash.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
setup command not found in Ubuntu 10.04 Command Prompt vinaytp Ubuntu 2 05-06-2010 01:10 PM
[SOLVED] export command deostroll Linux - Newbie 5 02-20-2010 06:55 AM
startx command in FC7 reverts me back to the command prompt sriram87 Linux - Newbie 5 01-03-2008 11:18 PM
Key stroke/command to shut down x and go into the command prompt screen? Fear58 Linux - General 1 07-14-2004 07:14 PM
Export Command choawk Linux - General 1 06-06-2003 01:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:00 PM.

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