bug-bash
[Top][All Lists]
Advanced

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

Is it normal for `bash -s foo` not to make PS1=foo available from ~/.bas


From: Torka Noda
Subject: Is it normal for `bash -s foo` not to make PS1=foo available from ~/.bashrc?
Date: Sat, 25 Mar 2017 05:40:18 +0100

Configuration Information [Automatically generated, do not
change]: Machine: x86_64
OS: linux-gnu
Compiler: x86_64-pc-linux-gnu-gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale'
-DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H   -I. -I./include -I.
-I./include -I./lib
-DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
-DSTANDARD_UTILS_PATH='/bin:/usr/bin:/sbin:/usr/sbin'
-DSYS_BASHRC='/etc/bash/bashrc'
-DSYS_BASH_LOGOUT='/etc/bash/bash_logout'
-DNON_INTERACTIVE_LOGIN_SHELLS -DSSH_SOURCE_BASHRC
-march=ivybridge -O2 -pipe -Wno-parentheses
-Wno-format-security uname output: Linux localhost 4.1.x-gentoo
#1 SMP PREEMPT Sun Mar 12 05:04:06 CET 2017 x86_64 Intel(R)
Core(TM) i7-3770 CPU @ 3.40GHz GenuineIntel GNU/Linux Machine
Type: x86_64-pc-linux-gnu

Bash Version: 4.4
Patch Level: 12
Release Status: release


Hi,

I've been searching for clean ways to pass data from a Bash
invocation, to my ~/.bashrc, to set my terminals up for
different uses.

It looks like `bash -s foo` should do the trick (I don't feed
any command to its stdin, but it should still set the
positional parameters, and continue starting up).

The problem is that while PS1=foo is available once Bash has
finished initializing (i.e., from the command line), it is not
available from my ~/.bashrc, during initialization.


~/.bashrc:
==============================
#!/bin/bash
if [ -n "$1" ]; then
        echo "\$1 set ($1)"
else
        echo '$1 not set!'
fi
==============================

$ bash -s foo
$1 not set! # <= $1 not available in ~/.bashrc.

$ echo $1
foo # <= $1 available afterward from the command-line.


Is it normal for Bash positional parameters not to be available
from ~/.bashrc during initialization?

I understand these positional parameters are supposed to be
passed to commands fed to Bash stdin, but I don't see any
reason why they shouldn't also be available from ~/.bashrc...

They are made available after initialization, anyway...

And they are technically part of Bash argument list (although
Bash options are skipped from the list here).


Workaround:

Start Bash with `env PROFILE=coding bash` and use PROFILE
instead, in my ~/.bashrc.


Thanks.



reply via email to

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