[ale] command doesn't work from script, only command line...
Keith Hopkins
hne at inetnow.net
Sat Dec 8 11:16:34 EST 2001
Christopher Bergeron wrote:
> Does anyone know why this command:
>
> cd `history | grep cd | grep -v grep | tail -n 2 | tail -n 1 | tr -s " " |
> cut -f 4 -d " "`
>
> works from the command line, but not from a [verbatim] shell script:
> #!/bin/bash
> cd `history | grep cd | grep -v grep | tail -n 2 | tail -n 1 | tr -s " " |
> cut -f 4 -d " "`
>
> I just named it p (for Previous) so I can switch to the directory I just
> came from. It doesn't work though. Any suggestions?
>
Hi Christopher,
It doesn't work for a couple of reasons.
1 (most importantly), a script forks a new process, and it does not inherit the parent's history. To verify this, just run a script only containing the history command. It will return nothing.
Try putting it in an alias instead of a script. That way it will run in the current shell process.
2) I think your second "tail" should actually be "head".
Lost in Tokyo,
Keith
---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be
sent to listmaster at ale dot org.
More information about the Ale
mailing list