bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is it normal for `bash -s foo` not to make 1=foo available from ~/.b


From: Torka Noda
Subject: Re: Is it normal for `bash -s foo` not to make 1=foo available from ~/.bashrc?
Date: Wed, 29 Mar 2017 17:05:09 +0200

On Wed, 29 Mar 2017 10:26:14 -0400
Greg Wooledge <wooledg@eeg.ccf.org> wrote:

> On Wed, Mar 29, 2017 at 04:10:14PM +0200, Torka Noda wrote:
> > Well, sorry for the confusion, I'll stop here. I think it's
> > weird for Bash's positional parameters, and the whole
> > argument list if modified with '-s', not to be accessible
> > from initialization files, but `env` does what I want
> > relatively simply compared to the tricks used by other
> > people on the web, and I'll be content with that.  
> 
> I'm still unclear on what you actually wanted to achieve.
> Bash doesn't normally *receive* any arguments when it's
> invoked as an interactive shell, because the things that
> would invoke it are usually terminal emulators that simply
> execute $SHELL, or shell escapes from terminal programs like
> vi, which again simply execute $SHELL.
> 


I have a script which opens the applications I want on all my
desks, including gnome-terminal with a few tabs.

In these tabs, I want to change the current directory (I could
use gnome-terminal's "--working-directory=$HOME/foo", but then
opening a new tab, when this tab is selected, would put me in
this initial directory, while I want to always start in
$HOME...), and run a few simple commands, like do an `ls` to
remind me the current content of the directory, or start `su`
so I only have to input my password... (it may not seem like
much, but doing it everyday for years, sometimes multiple times
a day, gets a bit annoying... plus laziness...).

So I need to be able to recognize which tab is being started,
from my ~/.bashrc, to execute the proper commands for this tab.

I start gnome-terminal, from a script bound to a keyboard key
(I prefer not to start everything automatically, in case I
just booted quickly for some simple thing, and don't want to get
my mail, RSS feeds, etc.), with:

gnome-terminal \
--tab -e 'env PROFILE=su /bin/bash' \
--tab -e 'env PROFILE=foo /bin/bash' \
--tab -e 'env PROFILE=bar /bin/bash' \
--tab

(If positional parameters were readable from ~/.bashrc, I could
use `-e '/bin/bash -s su'` instead, for example, and read "$1"
from by ~/.bashrc).

(I also use `xdotool` to place all my windows properly, and I
have a button to move/resize them afterward, if I move/resize
them temporarily for some task...).

... at the end of my ~/.bashrc, I have this:

==================================================

_PS1="$PS1"
_PS1="${_PS1//\\[}"
_PS1="${_PS1//\\]}"

case "$PROFILE" in
        su)
                echo -e "${_PS1@P}su"
                su
                ;;
        foo)
                cd "$HOME/foo"
                echo -e "${_PS1@P}ls"
                ls
                ;;
        bar)
                cd "$HOME/bar"
                echo -e "${_PS1@P}ls"
                ls
                ;;
        *)
                cd "$HOME"
                ;;
esac

unset -v _PS1 PROFILE

==================================================

(The _PS1 thing is just to print my prompt, with the name of the
command, before executing the command, for reference... and I
don't use PS1 directly, because it contains colors, and thus
\[ and \] sequences for proper line-wrapping, which need to be
stripped if printed directly, without going through readline
as a real prompt).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]