Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

screen running shell with another rc file

Posted on 2010-09-09
5
Medium Priority
?
736 Views
Last Modified: 2012-05-10
Hi, I have special configuration file for bash in some cases.

bash --noprofile --rc-file .mybashrc (I don't want to load the default one)

So I have s script where I run the command above.
But when I run a screen, it runs bash with default rc files and profile one.

so i tried to pass to screen as -s the script calling bash with rc file, but screen terminates immediately, no error thrown.

One last idea I have is merge my configs and direct loding based on some environment variable or so.

Are there other options?
0
Comment
Question by:DalHorinek
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
gremwell earned 1000 total points
ID: 33635659
One problem with your setup is that you have an unnecessary dash in 'rc-file' option, it should be:
 bash --noprofile --rcfile .mybashrc

When passing a value of -s parameter you have to specify a _path_ to a shell program, you cannot specify shell command there. Consider the following setup:

1. Your alternative Bash RC script:
abb@d820:~$ cat .bashrc_alt
echo Hi from .bashrc_alt
2. A wrapper around bash which will configure it as needed:
abb@d820:~$ cat bash_altrc
#!/bin/bash
exec bash --rcfile "$HOME/.bashrc_alt" $*

abb@d820:~$ ls -l bash_altrc
-rwxr-xr-x 1 abb abb 54 2010-09-09 13:49 bash_altrc
Now:

abb@d820:~$ bash
Hi from .bashrc
abb@d820:~$ exit

abb@d820:~$ ./bash_altrc
Hi from .bashrc_alt
abb@d820:~$ exit
After that

abb@d820:~$ screen -s /home/abb/bash_altrc
should invoke screen with alternative Bash rc script.
0
 
LVL 1

Expert Comment

by:pvzweden
ID: 33635694
You can use the -s option, however you need to tell screen that you are giving extra options to the shell.

Try: screen -s -- bash --noprofile  --rc-file .mybashrc

You need to place the -s option last. The "--" tells the command line it's the last option that is being given to the "screen" command.

Other option would indeed be to edit the default bashrc that get's called from your homedir to make a choice based on a profile option.

Patrick
0
 
LVL 3

Expert Comment

by:gremwell
ID: 33635754
I stand corrected, -s does not take an argument. Still, it should be --rcfile, not --rc-file.
0
 
LVL 1

Expert Comment

by:pvzweden
ID: 33635776
Gremwell, the --rc-file option is indeed incorrect.

From the man page:
 --rcfile file
              Execute commands from file instead of the standard personal initialization file ~/.bashrc if the shell is interactive (see INVOCATION below).
0
 
LVL 6

Author Comment

by:DalHorinek
ID: 33637080
I'm sorry for confusing by rc-file, sure it's rcfile.

gremwell, thanks, your way is working ok, that's what I tried, but I had an error somewhere, don't know where, and screen immediately terminated.

Now it's ok.

pvzweden

screen -s -- /bin/bash --noprofile --rcfile .mybashrc
Actually doesn't work, cuz it says Cannot exec '-': No such file or directory, because -s needs an argument, so it takes the following - (i don't know what it does with the other one - ) :)

Anyway thank you.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question