Discussion:
history utility
(too old to reply)
James B. Byrne
2016-05-20 18:17:09 UTC
Permalink
As is no doubt obvious from what I am trying to do I come from a bash
background.

While logged in as root I run the history command and see this:

# history
1 20:02 date 12:13:30
2 20:03 date 121350
3 13:51 man adjtime
4 13:51 apropos clock
5 13:52 apropos time
6 13:53 man adjkerntz
7 13:58 man clock
8 13:58 man hwclock
9 14:00 man date
. . .

I am used to bash and have this in my root .bash_profile on other
systems.

# Timestamp History
export HISTTIMEFORMAT='%F %T: '

Looking in the default ~/.profile I see this:

# $FreeBSD: releng/10.3/etc/root/dot.profile 199243 2009-11-13
05:54:55Z ed $
#
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:~/bin
export PATH
HOME=/root
export HOME
TERM=${TERM:-xterm}
export TERM
PAGER=more
export PAGER

Which to me implies that adding this should work.

echo "export HISTTIMEFORMAT='%F %T: '" >> .profile

But nooo. What I see from source .profile is:

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:~/bin:
Command not found.
export: Command not found.
HOME=/root: Command not found.
export: Command not found.
Bad : modifier in $ (-).

Which tells me that .profile is either processed differently than I
expect or not at all.

So, my questions are:

What is the purpose of .profile?
How is it used?
Why is there no export command found given that man sh explicitly
mentions the builtin command 'export'?
--
*** e-Mail is NOT a SECURE channel ***
Do NOT transmit sensitive data via e-Mail
Do NOT open attachments nor follow links sent by e-Mail

James B. Byrne mailto:***@Harte-Lyne.ca
Harte & Lyne Limited http://www.harte-lyne.ca
9 Brockley Drive vox: +1 905 561 1241
Hamilton, Ontario fax: +1 905 561 0757
Canada L8E 3C3
RW via freebsd-questions
2016-05-20 18:48:09 UTC
Permalink
On Fri, 20 May 2016 14:17:09 -0400
Post by James B. Byrne
As is no doubt obvious from what I am trying to do I come from a bash
background.
While logged in as root ...
Why is there no export command found given that man sh explicitly
mentions the builtin command 'export'?
The default logon shell for root is /bin/csh
Polytropon
2016-05-20 18:49:29 UTC
Permalink
Post by James B. Byrne
As is no doubt obvious from what I am trying to do I come from a bash
background.
# history
1 20:02 date 12:13:30
2 20:03 date 121350
3 13:51 man adjtime
4 13:51 apropos clock
5 13:52 apropos time
6 13:53 man adjkerntz
7 13:58 man clock
8 13:58 man hwclock
9 14:00 man date
. . .
Which shell is this? What does "echo $SHELL" report, and which
shell is defined for this user account in /etc/passwd's shell
field? Just to be sure...
Post by James B. Byrne
I am used to bash and have this in my root .bash_profile on other
systems.
# Timestamp History
export HISTTIMEFORMAT='%F %T: '
# $FreeBSD: releng/10.3/etc/root/dot.profile 199243 2009-11-13
05:54:55Z ed $
#
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:~/bin
export PATH
HOME=/root
export HOME
TERM=${TERM:-xterm}
export TERM
PAGER=more
export PAGER
Which to me implies that adding this should work.
echo "export HISTTIMEFORMAT='%F %T: '" >> .profile
Yes, this should work, if bash uses .profile. If I remember correctly,
it doesn't - instead it reads .bash_profile.

See "man bash" for the difference of .bash_profile and .bashrc.
Post by James B. Byrne
Command not found.
export: Command not found.
HOME=/root: Command not found.
export: Command not found.
Bad : modifier in $ (-).
Which tells me that .profile is either processed differently than I
expect or not at all.
This looks strange. You'll get this if you feed those commands
to the C shell (which doesn't use export, but setenv, and has
a different initialization file, .cshrc or .login).

Try with bash:

$ history
[...]
500 history
$ export HISTTIMEFORMAT='%F %T: '
$ history
[...]
502 2016-05-20 20:41:15: history

This probably is what you've expected. Now let's try C shell:

% history
[...]
178 20:44 history
% export HISTTIMEFORMAT='%F %T: '
export: Command not found.

To be expected.
Post by James B. Byrne
What is the purpose of .profile?
This is the profile file for /bin/sh, FreeBSD's default scripting
shell, and dialog shell for maintenance mode. It's a rewrite of
the classic Bourne shell, the (quite limited) predecessor of bash.
Post by James B. Byrne
How is it used?
As explained in "man sh". :-)
Post by James B. Byrne
Why is there no export command found given that man sh explicitly
mentions the builtin command 'export'?
Because it seems that you've issued the export command to the C shell,
which does not have it.

Regarding history timestamps, I think that the C shell does not have
that feature. However, you can use bash which obviously implements
it. You just need to start bash. ;-)
--
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
David Christensen
2016-05-21 03:41:53 UTC
Permalink
Post by RW via freebsd-questions
On Fri, 20 May 2016 14:17:09 -0400
Post by James B. Byrne
As is no doubt obvious from what I am trying to do I come from a bash
background.
While logged in as root ...
Why is there no export command found given that man sh explicitly
mentions the builtin command 'export'?
The default logon shell for root is /bin/csh
+1


Perhaps you want to enable/ configure your 'toor' account to use the
shell of your choosing:

https://duckduckgo.com/?q=freebsd+toor&t=ffsb&ia=web


David
Oscar Hodgson
2016-05-23 15:26:36 UTC
Permalink
Post by James B. Byrne
As is no doubt obvious from what I am trying to do I come from a bash
background.
Probably evil, but this in .cshrc works for me:

if ($?prompt) then
if ( -x /usr/local/bin/bash ) then
echo Switching to bash
exec /usr/local/bin/bash --login
fi
endif
Oscar Hodgson
2016-05-23 15:30:07 UTC
Permalink
Post by Oscar Hodgson
Probably evil,
Addendum ..

Also works for /bin/sh, of course. And if you use bash, at least install the statically linked version.
James B. Byrne via freebsd-questions
2016-05-23 21:53:58 UTC
Permalink
Post by Oscar Hodgson
Post by James B. Byrne
As is no doubt obvious from what I am trying to do I come from a
bash
background.
if ($?prompt) then
if ( -x /usr/local/bin/bash ) then
echo Switching to bash
exec /usr/local/bin/bash --login
fi
endif
I have done worse.

Thks.
--
*** e-Mail is NOT a SECURE channel ***
Do NOT transmit sensitive data via e-Mail
Do NOT open attachments nor follow links sent by e-Mail

James B. Byrne mailto:***@Harte-Lyne.ca
Harte & Lyne Limited http://www.harte-lyne.ca
9 Brockley Drive vox: +1 905 561 1241
Hamilton, Ontario fax: +1 905 561 0757
Canada L8E 3C3
Bertram Scharpf
2016-05-24 02:43:22 UTC
Permalink
Post by James B. Byrne via freebsd-questions
Post by Oscar Hodgson
As is no doubt obvious from what I am trying to do I come from a bash background.
if ($?prompt) then
if ( -x /usr/local/bin/bash ) then
echo Switching to bash
exec /usr/local/bin/bash --login
fi
endif
I have done worse.
+1

Could we all be wrong together without knowing of each other?

Bertram
--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de
Loading...