EzDevInfo.com

bashrc interview questions

Top bashrc frequently asked interview questions

Is it a good idea to put "screen -r" in my .bashrc?

I'd like to use screen to keep ssh sessions alive on my server. It would be nice if I could automatically resume any running session for my user when I log in. The straightforward way to do this would be adding "screen -r" to my .bashrc, and this seems to work fine. I'm just wondering if this will break anything under conditions which I haven't tested yet. Anyone with experience here who can tell me whether this is what I should do?


Source: (StackOverflow)

What does . .bashrc actually do?

When I enter a eg. a new alias into my .bashrc file I can't use it in that terminal window immediately and until recently I thought I had to restart the terminal to reload the .bashrc file. Then I found out somewhere that if I write

. .bashrc

this will reload the .bashrc file in the current window and I don't have to restart. This works fins but what is actually happening? Why does this reload the .bashrc file?


Source: (StackOverflow)

Advertisements

Bash prompt to change color when I am logged into a server

Is there a way to make the bash prompt dynamic, so that it changes color when logged into a server?

So I want the like the color to be green when on my system and change to red when connected to servers. I have huge number of servers I don't want to put a different .bashrc on all those.


Source: (StackOverflow)

How do I modify my git bash profile in Windows?

I'm using Git Bash on Windows 7 and would like to set up bash profile aliases such as alias gs='git status' to make my life easier. How can I do this?


Source: (StackOverflow)

iTerm/zsh not reading .bashrc OR .bash_profile

In ~/.bash_profile I have :

if [ -f ~/.bashrc ]; then
    source ~/.bashrc
fi

In ~/.bashrc I have some aliases

When I load a new iTerm window, my aliases do not work. If I source ~/.bashrc they work. If I source ~.bash_profile they work.

Isn't at least one of these supposed to be sourced automatically?

What might be causing it not to work properly?


Source: (StackOverflow)

Bash Alias Adding a Background Process

In my .bashrc, I want to put something like this.

alias lst='ls &'

So that I can do something like this.

$ lst /tmp

which will be translated into

$ ls /tmp &

How can I do the above?


Source: (StackOverflow)

What's the meaning of "rc" in filenames such as .vimrc and .bashrc? [duplicate]

This question already has an answer here:

There are many file with a name containing "rc", but what's the meaning of "rc"?


Source: (StackOverflow)

Bash not loading '.profile' in new session on Linux

I'm setting up a new Linux machine I got from our IT dept, and noticed .profile is not loaded when I start a new terminal session. The current shell is Bash, though I changed it from the default sh it came with. How do I make it load .profile on startup?

I access the shell via SSH: ssh myusername@remotemachine. I have administrator privileges on it.


Source: (StackOverflow)

How to execute python script from console without writing full path?

I have a few python scripts on /usr/share/scripts/ that I use often, and I want to be able to execute them by just writing the name and not the full path, how could I do this?

echo $PATH shows me:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/real/RealPlayer

So I tried writing on the terminal:

PATH="/usr/share/scripts/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/real/RealPlayer"
export

No errors shown and echo $PATH now shows my new scripts path, but when I run scriptName I get command not found.

What am i doing wrong?


Source: (StackOverflow)

Why do people source bash_profile from bashrc instead of the other way round?

It sounds like most terminal emulators don't run local sessions as login by default, so they'll load bashrc rather than bash_profile. So why do most people put everything in bash_profile and have bashrc source it rather than the other way around? By "most people" I mean most people I've seen so far. Maybe it's not as widespread as I think.

Instead of putting our configuration there and having bashrc source bash_profile, wouldn't it make more sense and be more consistent with the linux community to put everything in bashrc and have bash_profile source that?

I've heard good things about iTerm2, and it sounds like that and just about every other terminal emulator out there (other than the default OSX Terminal) would end up loading bashrc when I'm running locally. Not that it matters, as long as one sources the other, but I'm confused why preferring bash_profile is the standard?

Minor side-note: I was mistaken about iTerm2. It defaults to running login sessions, just like Terminal.app, though both emulators appear to have an option that lets you alter that.


Source: (StackOverflow)

Putty solarized the manual way

I would like to use the solarized color scheme in PuTTY. The tricky part is I don't have administrator privileges in this machine. So I will have to manually change the default colors through Change Settings > Window > Colors.

I'm looking for a correspondence table with solarized RGB colors and PuTTY color names:

  • Default Foreground
  • Default Bold Foreground
  • Default Background
  • Default Bold Background
  • Cursor Text
  • Cursor Colour
  • ANSI Black
  • ANSI Black Bold
  • ANSI Red
  • ANSI Red Bold
  • ANSI Green
  • ANSI Green Bold
  • ANSI Yellow
  • ANSI Yellow Bold
  • ANSI Blue
  • ANSI Blue Bold
  • ANSI Magenta
  • ANSI Magenta Bold
  • ANSI Cyan
  • ANSI Cyan Bold
  • ANSI White
  • ANSI White Bold

I also accept any color scheme that is remotely better than PuTTY's default...

EDIT:

A saner way of doing this is to tick all the boxes in Settings -> Windows -> Colour and then, in the remote machine, add the line

export TERM=xterm-256color

or

export TERM=xterm

to ~/.bashrc and create the file ~\.Xresources with the Solarized color scheme.


Source: (StackOverflow)

Adding git branch to bash prompt on snow leopard

I am using this:

$(__git_ps1 '(%s)')

It works however it does not update when I change directories or checkout a new branch. I also have this alias:

alias reload='. ~/.bash_profile'

Sample run:

user@machine:~/dev/rails$cd git_folder/
user@machine:~/dev/rails/git_folder$reload
user@machine:~/dev/rails/git_folder(test)$git checkout master
Switched to branch 'master'
user@machine:~/dev/rails/git_folder(test)$reload
user@machine:~/dev/rails/git_folder(master)$

As you can see it is being set correctly but only if I reload bash_profile. I have wasted way to much time on this. I am using bash on snow leopard. Please help!

Edit: You can see my dotfiles on github and the file setting the PS1 here


Source: (StackOverflow)

bash: execute command given in commandline and don't exit

how do I specifiy a command on the commmandline of bash which shall be executed once inside the new bash after reading ~/.bashrc -- But all this without letting bash exit after the command is finished?

I'm fiddling around with a "boot-up-configuration" for terminator where some splits should start some applications (vim, mutt, irrsi) after startup. But I still want normal shells in the background (ctrl-z and so on...) so after quitting an application I have the same shell which I had during the eapplications lifetime...

What does not work for me (based on given answers)

 ( bash; vim )              # vim waits for the exit of bash...
 bash -c vim                # bash exits after vims exit...
 bash -c 'vim; exec bash'   # bash is executed _after_ vim... ctrl-z won't work
 echo vim | bash -s         # "Vim: Warning: Input is not from a terminal"     

Manually appending "vim" to a temporary bashrc does not work either. vim starts up correctly, but there is still no background bash present where a ctrl-z would bring me to.

Any suggestions?


Source: (StackOverflow)

Where's .bashrc for root?

I know it's not best practice, but on my dev system I login as root. What's the equivalent of the .bashrc file so I can alias some functions?

I've found the /etc/bash.bashrc & /etc/bash.bashrc.local but I'm not sure where to plop my commands.

Running x86_64 SUSE.

thanks, mjb.


Source: (StackOverflow)

What's the difference between /etc/bash.bashrc and ~/.bashrc? Which one should I use?

When should I use each of the two .bashrc files to set my aliases, prompt, etc?


Source: (StackOverflow)