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 - 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 01-24-2013, 04:36 PM   #1
mdewell
LQ Newbie
 
Registered: Jan 2013
Posts: 9

Rep: Reputation: Disabled
.kshrc returns 'command not found' for newlines


Hello,

I'm trying to switch to a k shell for my base, and Ive set the line:

export ENV=$HOME/.kshrc

in my .profile and the /etc/passwd has /bin/ksh as its entry.

When I login, it appears to try and process my .kshrc but for the newlines it returns a "command not found" and that makes me think it's not working properly, as my function(s) I put in there aren't working.

Any thoughts on how to test the reason for the error and to fix it so that my .kshrc gets executed?

Thanks in advance.
 
Old 01-24-2013, 05:03 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Show the .kshrc file contents (& .profile).
How did you create the files?
 
Old 01-24-2013, 09:09 PM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Once after login, invoke following cmd to check your shell:-
Code:
~$ echo $SHELL
If it results in ksh, then you can set any new environment variable in your .kshrc as:
Code:
export ENV=$HOME/.kshrc
Or simply,
ENV=$HOME/.kshrc
And then recharge the file to take it into effect as:-
Code:
~$ source .kshrc
If it still gives same error, then comment out this line from your .kshrc and recharge the file again to check whether error is because of this line or any other entry:
Code:
~$ vi .kshrc
# ENV=$HOME/.kshrc
Also share result of:
Code:
~$ source .profile
~$ which export
 
Old 01-25-2013, 07:09 AM   #4
mdewell
LQ Newbie
 
Registered: Jan 2013
Posts: 9

Original Poster
Rep: Reputation: Disabled
.profile and .kshrc

Sorry guys,

I got tied up with some other things.

Here's my .profile

----------------------------------------------------------------------------------------------
#! /bin/ksh
#
# profile.ksh
#
# Korn shell profile

#ident $Id: shell,v 1.1.1.1 2002/08/06 20:45:09 build Exp $ (OSM Ltd. - COSuser)

[ -f $HOME/.Printer ] && . $HOME/.Printer

export EDITOR=emacs # set to vi or emacs
export PWD
#export PAGER="pg -csn" # choose your favourite pager

export ENV=$HOME/.kshrc

----------------------------------------------------------------------------------------------

Here's my .kshrc

----------------------------------------------------------------------------------------------

# .kshrc -- Commands executed by the Korn shell at startup
#
# Set environmental variables

# Set command line prompt
PS1='${HOSTNAME}:${PWD} >'

#
# Some useful aliases here:
#
alias cd..="cd .."
alias copy="cp"
alias del="rm"
alias hist="history"
alias help="man"
alias ren="mv"
alias type="cat"

#
# change arrow commandline habits
#
alias __A=`echo "\020"`
alias __B=`echo "\016"`
alias __C=`echo "\006"`
alias __D=`echo "\002"`
alias __H=`echo "\001"`
alias __Y=`echo "\005"`

#
# entries added from Chad D. Young's .profile
#
export HISTFILE=${HOME}/.sshistory
export EXINIT="set showmode"
export HZ=100
# export MAIL=/usr/mail/${LOGNAME:?}
# export PATH=$PATH:/usr/local/bin:/usr/pub:/wic/client/bin:/usr/local/bin/optical:.
export PATH=$PATH:/usr/pub:/wic/client/bin:/usr/local/bin/optical:.
# export PGPPATH=/wic/home/wi/.pgp
# export PGPPASS=west
export SHELL=/bin/ksh
# export TERM=vt100
export VISUAL=/usr/bin/vi
export HOST=`hostname`
# export CVS_RSH=remsh
# export CVS_SERVER=/usr/local/bin/cvs
# export CVSROOT=:ext:$LOGNAME@ibm32:/wic/cvs
# export CVS_SERVER=/wic/local/bin/cvs
# export CVSROOT=/wic/cvs
# export CVS_RSH=rsh
# export CVSUMASK=000

#
# funtion to use as 'dir' command
#
function adir(){
ls -la $1 | grep "^d" && ls -la $1 | grep "^-" && ls -la $1 | grep "^l" | more;
}

function dir(){
ls -l $1 | grep "^d" && ls -l $1 | grep "^-" && ls -l $1 | grep "^l";
}
----------------------------------------------------------------------------------------------

I hope this helps to findout what's wrong.

Thanks
 
Old 01-25-2013, 07:15 AM   #5
mdewell
LQ Newbie
 
Registered: Jan 2013
Posts: 9

Original Poster
Rep: Reputation: Disabled
which export

Hello shivaa,

Here's what i get from 'source .profile; which export'

linux2441:/wic/home/mmdewell >which export
/usr/bin/which: no export in (/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/opt/informix/bin:/usr/pub:/wic/client/bin:/usr/local/bin/optical:.::/usr/pub:/wic/client/bin:/usr/local/bin/optical:.)

Thanks for your help, yet I'm still getting errors. We can figure this out.
 
Old 01-25-2013, 07:17 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
you need (must) not start your .profile with #!/bin/ksh. instead, you can add set -x to check what's happening. There were some additional questions: how did you create that file? what is the exact result of source .profile? also please try echo $0, and show the answer

Last edited by pan64; 01-25-2013 at 07:18 AM.
 
Old 01-25-2013, 07:20 AM   #7
mdewell
LQ Newbie
 
Registered: Jan 2013
Posts: 9

Original Poster
Rep: Reputation: Disabled
Hello pan64,

I get no result from 'source .profile', i.e. just a new prompt.

Would you be kind enough to explain about the '#!/bin/ksh' and why not to use it?

Thank you very much.
 
Old 01-25-2013, 07:25 AM   #8
mdewell
LQ Newbie
 
Registered: Jan 2013
Posts: 9

Original Poster
Rep: Reputation: Disabled
Hello pan64,

Well, the removal of '#!/bin/ksh' appears to have done it, though I'm not sure what you mean with the 'set -x' command. Where in do I need to put 'set -x'? Do I need to put it in .profile or .kshrc? And where in that (what line or place with the order of things) do I need to write it?

Thanks so much
 
Old 01-25-2013, 07:29 AM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
so a script is executed always by an interpreter. In general you can use shebang (#! at the beginning of the file) to define the interpreter to be used to execute the current script. So you can enter #!perl, #!bash or whatever you need. The source <file> command means the file will be executed by the current shell, therefore the shebang is not evaluated and also can be misleading. for example ~/.profile is used by bash, ksh and zsh too.
see for example here: http://stackoverflow.com/questions/1...of-a-file-mean
 
Old 01-25-2013, 07:32 AM   #10
mdewell
LQ Newbie
 
Registered: Jan 2013
Posts: 9

Original Poster
Rep: Reputation: Disabled
WHOOPS!!!

Spoke to soon! I forgot that I still had passwd with /bin/bash for my login. So, I fixed that and I'm still getting this error on login:

: not foundome/mmdewell/.kshrc[4]:
: not foundome/mmdewell/.kshrc[7]:
alias not found
: not foundome/mmdewell/.kshrc[18]:
: not foundome/mmdewell/.kshrc[28]:
: not foundome/mmdewell/.kshrc[51]:
ksh: /???/home/mmdewell/.kshrc[55]: syntax error: `(' unexpected

I used '???' to protect some other information that might reveal too much information about where this problem is at.

Thanks again, in advance.
 
Old 01-25-2013, 08:18 AM   #11
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Originally Posted by mdewell View Post
Hello shivaa,

Here's what i get from 'source .profile; which export'

linux2441:/wic/home/mmdewell >which export
/usr/bin/which: no export in (/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/opt/informix/bin:/usr/pub:/wic/client/bin:/usr/local/bin/optical:.::/usr/pub:/wic/client/bin:/usr/local/bin/optical:.)
As you can see, export command is not available in ksh. So the error of "command not found" can be because of this entry in .kshrc:-
Code:
export ENV=$HOME/.kshrc
So either remove export keyword:-
Code:
ENV=$HOME/.kshrc
Or simply comment out this line:-
Code:
# export ENV=$HOME/.kshrc
After this, once source .kshrc to take changes into effect.

Last edited by shivaa; 01-25-2013 at 08:21 AM. Reason: Formatting
 
Old 01-25-2013, 11:48 AM   #12
mdewell
LQ Newbie
 
Registered: Jan 2013
Posts: 9

Original Poster
Rep: Reputation: Disabled
Hello shivaa,

I tried to 'source' at the commandline and it's not finding it. I did a 'whereis source' and it only gave me a 'man' page entry. So, I 'man'ed source and it said things about 'bash' and nothin about 'ksh' in the man-page. Any thoughts? Is it just not in my PATH?

Thanks.
 
Old 01-25-2013, 12:10 PM   #13
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Command source is used to recharge i.e. re-read specified file. Well, I don't understand, you've used source .profile , but now why there's no source?

Anyway, if source isn't there, then exit from your current terminal and open a new one. It will re-read your shell initialization file(s) and will take modified ones into effect. Also check if you still get "command not found" error or not.

Alternatively, you can source files as:-
Code:
~$ . <filename>
Or you can try:-
Code:
~$ sh .kshrc
 
Old 01-25-2013, 02:16 PM   #14
mdewell
LQ Newbie
 
Registered: Jan 2013
Posts: 9

Original Poster
Rep: Reputation: Disabled
I still seem to be getting errors:

linux2441:/???/home/mmdewell >ksh .kshrc
: not found
: not found
alias not found
: not found
: not found
: not found
.kshrc[55]: syntax error: `(' unexpected
 
Old 01-25-2013, 07:26 PM   #15
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
I tested the .kshrc that you provided and found that this error is because of "function" keyword before function names in it, so simply remove "fuction" keyword, and source .kshrc again (by exiting and opening a new terminal).
Or copy the new .kshrc from here:
Code:
# .kshrc -- Commands executed by the Korn shell at startup
#
# Set environmental variables

# Set command line prompt
PS1='${HOSTNAME}:${PWD} >'

#
# Some useful aliases here:
#
alias cd..="cd .."
alias copy="cp"
alias del="rm"
alias hist="history"
alias help="man"
alias ren="mv"
alias type="cat"

#
# change arrow commandline habits
#
alias __A=`echo "\020"`
alias __B=`echo "\016"`
alias __C=`echo "\006"`
alias __D=`echo "\002"`
alias __H=`echo "\001"`
alias __Y=`echo "\005"`

#
# entries added from Chad D. Young's .profile
#
export HISTFILE=${HOME}/.sshistory
export EXINIT="set showmode"
export HZ=100
# export MAIL=/usr/mail/${LOGNAME:?}
# export PATH=$PATH:/usr/local/bin:/usr/pub:/wic/client/bin:/usr/local/bin/optical:.
export PATH=$PATH:/usr/pub:/wic/client/bin:/usr/local/bin/optical:.
# export PGPPATH=/wic/home/wi/.pgp
# export PGPPASS=west
export SHELL=/bin/ksh
# export TERM=vt100
export VISUAL=/usr/bin/vi
export HOST=`hostname`
# export CVS_RSH=remsh
# export CVS_SERVER=/usr/local/bin/cvs
# export CVSROOT=:ext:$LOGNAME@ibm32:/wic/cvs
# export CVS_SERVER=/wic/local/bin/cvs
# export CVSROOT=/wic/cvs
# export CVS_RSH=rsh
# export CVSUMASK=000

#
# funtion to use as 'dir' command
#
adir(){
ls -la $1 | grep "^d" && ls -la $1 | grep "^-" && ls -la $1 | grep "^l" | more;
}

dir(){
ls -l $1 | grep "^d" && ls -l $1 | grep "^-" && ls -l $1 | grep "^l";
}
Second thing, once confirm your default shell:
Code:
grep 'mmdewell' /etc/passwd
It's last field will give you your default shell.

Last edited by shivaa; 01-25-2013 at 07:32 PM. Reason: Addition
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Removing newlines from output of cat command MahendraL Programming 5 12-20-2012 06:35 AM
[SOLVED] apt-get install pkg_name returns "update-alternatives: command not found" bpeacocke Linux - Software 5 10-12-2011 09:16 PM
If 'host' returns not found... SentralOrigin Linux - Networking 1 08-31-2010 07:43 PM
alsaconf returns error msg "getopt: command not found" bezdomny Linux - Hardware 4 07-13-2007 09:20 AM
executing a loaded module returns "command not found" error neelay1 Linux - Software 1 05-08-2006 02:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:05 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