[Top][All Lists]

[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
-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


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.

if [ -n "$1" ]; then
        echo "\$1 set ($1)"
        echo '$1 not set!'

$ 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).


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


reply via email to

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