emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* bash alias and history in code block
@ 2013-12-06 17:58 OSiUX
  2013-12-06 18:34 ` Eric Schulte
  2013-12-06 19:23 ` Sebastien Vauban
  0 siblings, 2 replies; 4+ messages in thread
From: OSiUX @ 2013-12-06 17:58 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 509 bytes --]

How to use alias and bash builtin functions?

 #+BEGIN_SRC sh :session :results output
   echo $SHELL
   echo $HOME
   source ~/.bashrc
   alias | wc
   env | grep HISTTIMEFORMAT
   history | wc
 #+END_SRC

 #+RESULTS:
 : /bin/bash
 : /home/osiris
 :       0       0       0
 : HISTTIMEFORMAT=%Y-%m-%d %H:%M
 :       0       0       0

Thanks!

--

::

  Osiris Alejandro Gomez (OSiUX) osiux@osiux.com.ar
  DC44 95D2 0D5D D544 FC1A F00F B308 A671 9237 D36C
  http://www.osiux.com.ar http://www.altermundi.net

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: bash alias and history in code block
  2013-12-06 17:58 bash alias and history in code block OSiUX
@ 2013-12-06 18:34 ` Eric Schulte
  2013-12-06 19:23 ` Sebastien Vauban
  1 sibling, 0 replies; 4+ messages in thread
From: Eric Schulte @ 2013-12-06 18:34 UTC (permalink / raw)
  To: OSiUX; +Cc: emacs-orgmode

OSiUX <xuiso@osiux.com.ar> writes:

> How to use alias and bash builtin functions?
>
>  #+BEGIN_SRC sh :session :results output
>    echo $SHELL
>    echo $HOME
>    source ~/.bashrc
>    alias | wc
>    env | grep HISTTIMEFORMAT
>    history | wc
>  #+END_SRC
>
>  #+RESULTS:
>  : /bin/bash
>  : /home/osiris
>  :       0       0       0
>  : HISTTIMEFORMAT=%Y-%m-%d %H:%M
>  :       0       0       0
>
> Thanks!
>

I get the following.  Note that I define my alia in a separate file
which I had to load explicitly for the alia to be defined (it should be
sourced from my ~/.bashrc, but shells can be weird about loading things
they think might be profile related when you're not logging in).

#+BEGIN_SRC sh :session :results output
  echo $SHELL
  echo $HOME
  source ~/.bashrc
  alias | wc
  env | wc
  history | wc
#+END_SRC

#+RESULTS:
: /bin/zsh
: /home/eschulte
:       0       0       0
:      28      28     715
:       0       0       0

#+BEGIN_SRC sh :session :results output
  echo $SHELL
  echo $HOME
  source ~/.alia
  source ~/.bashrc
  alias | wc
  env | wc
  history | wc
#+END_SRC

#+RESULTS:
: /bin/zsh
: /home/eschulte
:      19      99     814
:      28      28     715
:       0       0       0

My guess with the empty history is that bash can tell it isn't an
interactive session, which you might be able to fake with tty pipe STDIN
and STDOUT nonsense in ob-sh.  But in general I don't see the utility of
history in a code block.

Best,

-- 
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: bash alias and history in code block
  2013-12-06 17:58 bash alias and history in code block OSiUX
  2013-12-06 18:34 ` Eric Schulte
@ 2013-12-06 19:23 ` Sebastien Vauban
  2013-12-06 20:16   ` OSiUX
  1 sibling, 1 reply; 4+ messages in thread
From: Sebastien Vauban @ 2013-12-06 19:23 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

OSiUX wrote:
> How to use alias and bash builtin functions?
>
>  #+BEGIN_SRC sh :session :results output
>    echo $SHELL
>    echo $HOME
>    source ~/.bashrc
>    alias | wc
>    env | grep HISTTIMEFORMAT
>    history | wc
>  #+END_SRC
>
>  #+RESULTS:
>  : /bin/bash
>  : /home/osiris
>  :       0       0       0
>  : HISTTIMEFORMAT=%Y-%m-%d %H:%M
>  :       0       0       0

Just throwing an idea (as I don't know enough about that): play with the
variable `org-babel-sh-command' (default: "bash") and add options such as
"--login" or "--interactive" (or stuff like that)?

Best regards,
  Seb

-- 
Sebastien Vauban

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: bash alias and history in code block
  2013-12-06 19:23 ` Sebastien Vauban
@ 2013-12-06 20:16   ` OSiUX
  0 siblings, 0 replies; 4+ messages in thread
From: OSiUX @ 2013-12-06 20:16 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2013 bytes --]

El vie, 06 dic 2013, Sebastien Vauban decía:

> OSiUX wrote:
> > How to use alias and bash builtin functions?
> >
> >  #+BEGIN_SRC sh :session :results output
> >    echo $SHELL
> >    echo $HOME
> >    source ~/.bashrc
> >    alias | wc
> >    env | grep HISTTIMEFORMAT
> >    history | wc
> >  #+END_SRC
> >
> >  #+RESULTS:
> >  : /bin/bash
> >  : /home/osiris
> >  :       0       0       0
> >  : HISTTIMEFORMAT=%Y-%m-%d %H:%M
> >  :       0       0       0
>
> Just throwing an idea (as I don't know enough about that): play with the
> variable `org-babel-sh-command' (default: "bash") and add options such as
> "--login" or "--interactive" (or stuff like that)?

Ok, add a "bash -i" and now is working well:

   #+BEGIN_SRC sh :session :results output
     grep bash ~/.emacs
     echo $SHELL
     echo $HOME
     alias | wc
     env | grep HISTTIMEFORMAT
     echo $BASH_VERSION
     shopt -s histappend
     set -o | grep history
     history | wc
     alias dia
     alias hh
     hh | tail
     history -a
   #+END_SRC

   #+RESULTS:
   #+begin_example
   (setq org-babel-sh-command "bash -i")
   /bin/bash
   /home/osiris
       534    3236   29894
   HISTTIMEFORMAT=%Y-%m-%d %H:%M
   4.2.37(1)-release
   history          on
      8275   44194  338107
   alias dia='date +%Y-%m-%d'
   alias hh='history | egrep $(dia)  | cut -c 19- | sort -u'
   17:10 set -o | grep history
   17:10 shopt -s histappend
   17:10 ssh sugar-mant
   17:10 sudo chown osiris.osiris config -R
   17:10 sudo chown osiris.osiris .* -R
   17:10 sudo chown osiris.osiris /var/run/screen/S-osiris
   17:10 sudo chown osiris.osiris /var/run/screen/S-osiris.*
   17:10 sudo -s
  #+end_example

Sometimes I forget to start clock in a task,
then I use the history to know the timestamp
:-P

--

::

  Osiris Alejandro Gomez (OSiUX) osiux@osiux.com.ar
  DC44 95D2 0D5D D544 FC1A F00F B308 A671 9237 D36C
  http://www.osiux.com.ar http://www.altermundi.net

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-12-06 20:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-06 17:58 bash alias and history in code block OSiUX
2013-12-06 18:34 ` Eric Schulte
2013-12-06 19:23 ` Sebastien Vauban
2013-12-06 20:16   ` OSiUX

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).