From: no.top.post on
Other one-line scripts do their jobs.
Why not this one ?

[root(a)localhost eas]# ib ; pwd
/home/eas
[root(a)localhost eas]# whereis ib
ib: /usr/local/bin/ib
[root(a)localhost eas]# cat /usr/local/bin/ib
cd /mnt/p11
[root(a)localhost eas]# pwd
/home/eas
[root(a)localhost eas]# cd /mnt/p11
[root(a)localhost p11]# pwd
/mnt/p11
[root(a)localhost p11]# ls -l /usr/local/bin/ib
-rwxr-xr-x 1 root root 13 Jul 27 14:19 /usr/local/bin/ib*
---------
OK, after writing this, I realised the 'cd' only holds while the script
is active. So then I tried 'alias'; but it seems to only apply to the
originating VT. So what should I do to short-cut various 'cdS'?


TIA.


From: Chris F.A. Johnson on
On 2010-08-01, no.top.post(a)gmail.com wrote:
> Other one-line scripts do their jobs.
> Why not this one ?
>
> [root(a)localhost eas]# ib ; pwd
> /home/eas

Why are you playing around using the root account?

> [root(a)localhost eas]# whereis ib
> ib: /usr/local/bin/ib
> [root(a)localhost eas]# cat /usr/local/bin/ib
> cd /mnt/p11
> [root(a)localhost eas]# pwd
> /home/eas
> [root(a)localhost eas]# cd /mnt/p11
> [root(a)localhost p11]# pwd
> /mnt/p11
> [root(a)localhost p11]# ls -l /usr/local/bin/ib
> -rwxr-xr-x 1 root root 13 Jul 27 14:19 /usr/local/bin/ib*
> ---------
> OK, after writing this, I realised the 'cd' only holds while the script
> is active. So then I tried 'alias'; but it seems to only apply to the
> originating VT. So what should I do to short-cut various 'cdS'?

In order for a script to affect the current environment it must be
sourced:

.. ib

Or (bash only):

source ib

--
Chris F.A. Johnson, <http://cfajohnson.com>
Author:
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
From: Rahul on
no.top.post(a)gmail.com wrote in news:i3487h$vcm$1(a)news.eternal-
september.org:

> OK, after writing this, I realised the 'cd' only holds while the script
> is active. So then I tried 'alias'; but it seems to only apply to the
> originating VT. So what should I do to short-cut various 'cdS'?
>

Write an alias and put it in your .bashrc / .cshrc. Automatically active in
new shells you open. Need to soourc .bashrc in the current shell. Does that
work?

--
Rahul
From: Joseph Rosevear on
In alt.os.linux.slackware no.top.post(a)gmail.com wrote:
> Other one-line scripts do their jobs.
> Why not this one ?
>
> [root(a)localhost eas]# ib ; pwd
> /home/eas
> [root(a)localhost eas]# whereis ib
> ib: /usr/local/bin/ib
> [root(a)localhost eas]# cat /usr/local/bin/ib
> cd /mnt/p11
> [root(a)localhost eas]# pwd
> /home/eas
> [root(a)localhost eas]# cd /mnt/p11
> [root(a)localhost p11]# pwd
> /mnt/p11
> [root(a)localhost p11]# ls -l /usr/local/bin/ib
> -rwxr-xr-x 1 root root 13 Jul 27 14:19 /usr/local/bin/ib*
> ---------
> OK, after writing this, I realised the 'cd' only holds while the script
> is active. So then I tried 'alias'; but it seems to only apply to the
> originating VT. So what should I do to short-cut various 'cdS'?
>
>
> TIA.

Notop,

I agree with the alias and sourcing approaches and would like to add
one more.

Write a script that defines a function. Functions operate on the
current environment, but you have to define them before you use them.
The definition becomes part of your environment, and will last until it
is "unset" or you close the shell.

Here is a short function:


function ib() {

cd /mnt/p11
}


Function ib can be defined any of these ways:

1. Type the above at the command line.
2. Make a script out of the above, then source it. (Call the script
define_ib. Source it with "source define_ib".)
3. Put "source define_ib" in your ~/.profile file, and it will be
defined automatically when you login.

To use function ib, just enter "ib" at the command line. If you need
to un - define function ib for some reason use "unset ib". To see what
functions are currently defined use "set" or "set | less".

-Joe