2
votes
3answers
43 views

bash: dynamic environment control

I have an application which modifies environment variables. The intent is to launch a bash shell with a modified context-specific environment. When my application modifies the environment, and ...
1
vote
1answer
19 views

'script' session logging makes me exit twice

I'm using a solution described here to log my shell sessions, by adding this to the end of /etc/bash.bashrc: test "$(ps -ocommand= -p $PPID | awk '{print $1}')" == 'script' || (script -f ...
0
votes
2answers
35 views

Point program without garbaging up alias (~/.bashrc)

What is the correct way to point to a program/script without passing the command through aliases in the bashrc? For example: I create a custom script MyScript.sh. I wish to create a command that can ...
2
votes
1answer
26 views

Change the PS1 prompt in a subshell sh called from parent bash

When I am running an interactive bash session, I sometimes experiment with sh. I call sh directly from this bash session. My question is, how can I change the PS1 prompt of this subshell? I would ...
16
votes
2answers
461 views

How to retrieve lost aliases?

Let me start by saying I know this was dumb. Time and Linux make fools of us all. I made an echo command to my .bash_aliases file and erased all of my aliases, except the test alias. However, I ...
5
votes
1answer
71 views

Linux: $SSH_CONNECTION is set even without SSHing to the server

I have a remote server and I am writing a script in the server and want it to fire only when I SSH. I thought of using the $SSH_CONNECTION and $SSH_TTY for this purpose. I found out that when I have ...
4
votes
1answer
94 views

PS: what does “ps -o comm= -p $PPID” do

I have a script which does ps -o comm= -p $PPID. The explanation says this gets the parent process name. From the man page I found out -o means user defined format, comm means command and -p means ...
3
votes
3answers
149 views

Messed up bash.bashrc file, commands not working anymore

Trying installing Java, I tried to add it to the executable path with the line: export PATH=/usr/lib/jvm/jdk1.7.0_60/bin:$PATH in the system-wide /etc/bash.bashrc file. For some reason this ...
6
votes
4answers
142 views

disabling job control in bash (CTRL-Z)

It happens to me sometimes, that I press CTRL+Z by accident and my application disappears into background. I know, I can bring it back with fg, so it's not such a big deal. But I am wondering about ...
2
votes
2answers
225 views

What is the purpose of .bashrc and how does it work?

I found the .bashrc file and I want to know the purpose/function of it. Also how and when is it used?
1
vote
1answer
177 views

Terminal, Prompt changed to “-Bash-4.2” and colors lost

Usually my terminal prompt was username place$ now it only shows bash-4.2$ and all the color settings have been lost (on the terminal profile I have the same color scheme, but it just don't show ...
3
votes
2answers
226 views

How can I use nested [] to replace a if-then-fi ? (“[: -f: binary operator expected”)

In my .bashrc file I have: if [ -f /etc/bash_completion ] && ! shopt -oq posix; then . /etc/bash_completion; fi I wanted to use [] around it instead of if then fi I already have [ -f ...
0
votes
1answer
130 views

RVM + TMUX—Duplicate entries in $PATH

My Linux terminal config files (.bash_profile, .profile, .bashrc) expand $PATH by prepending some custom directories. This only happens once (and I've also included some ENV vairiable based guards to ...
5
votes
3answers
91 views

How can I make my .bashrc call to shopt -s autocd depend on the bash version?

In Ubuntu I like having shopt -s autocd in my .bashrc file for automatic CD'ing with typing 'cd', i.e. just type the directory name (and probably use tab completion too) and press return and be ...
2
votes
2answers
80 views

bashrc that calls other bashrc depending on linux distro

I login to a system that reads my bashrc file and loads some software ready to use. I'd like to load a given bashrc file depending on the linux system that I am logging into. Specifically, if I am ...
6
votes
1answer
132 views

Is there a Bash file that will be always sourced in interactive mode no matter if it is login or non-login?

As far as I know the interactive shells may be login or not login and the start up files for them are different. If interactive + login shell → /etc/profile then the first readable of ...
0
votes
3answers
120 views

How to create a permanent alias without resourcing the .bashrc-like file?

I really like bash aliases, it annoys me that every time I want to add a new alias I have type two commands: echo "alias \"short-cmd\"='long-command'" >> ~/.bash_aliases source ~/.bash_aliases ...
3
votes
2answers
135 views

Setting tabstop for bash output

Is it possible to set a tabstop (number of spaces per tab) for the more and less commands? In vi, I've added this line to .vimrc set tabstop=4 However when I read through a file with more it still ...
0
votes
2answers
169 views

How to write an alias function to make dd show progress bar?

According to this article, by replacing: $ dd if=/dev/sda of=/dev/sdb [additional options] with: $ pv -tpreb /dev/sda | dd of=/dev/sdb [additional options] one can augment the default dd ...
2
votes
4answers
95 views

Defining aliases for a certain directory

Is there a way to have an alias set for a particular directory and its subdirectories? I know I can put it in my .bashrc file, but I would like it only for a certain directory. Edit: what i mean is ...
3
votes
1answer
44 views

Why did my “d” break when I screwed up a bind?

I was swapping some readline settings in my .bashrc earlier today and mistyped the following (bind since it's not in .inputrc): bind "mark-symlinked-directories on" I forgot to put a set in there ...
0
votes
1answer
39 views

Using !n in script or interactive mode

I add to ~/.bashrc the following code: test_exclamation () { printf %s "$READLINE_LINE" | xargs echo } bind -x '"\eX": test_exclamation' I write to bash prompt buffer $ !1700 If I press Enter, ...
2
votes
1answer
94 views

How to make an alias active in both current session and in .bashrc at same time?

I just found frequently I decide to add an alias for longer time use at the same time use it now. So I have to type the same thing twice, first in current bash session then .bashrc.
9
votes
2answers
774 views

using export in .bashrc

I have noticed in my .bashrc, that some lines have export in front, such as export HISTTIMEFORMAT="%b-%d %H:%M " ... export MYSQL_HISTFILE="/root/.mysql_history" whereas other have not, such as ...
8
votes
2answers
178 views

How can I create a local function in my bashrc?

My .bashrc had some code that was repetitive so I used a function to simplify it do_stuff() { local version=$1 export FOO_${version}_X="17" export FOO_${version}_Y="42" } do_stuff '5.1' ...
24
votes
3answers
547 views

Multicolored Grep

I'm trying to get each grep command to highlight it's results in a different color. I can do it manually with a line like this: ls -l GREP_COLORS='mt=01;32' grep c | GREP_COLORS='mt=01;31' grep o | ...
7
votes
3answers
131 views

In shell config scripts, how can I account for differences between coreutils on BSD compared to GNU?

Up until this month, my shell configs have been pretty simple (just a .bashrc or .bash_profile with some aliases mainly), but I have been refactoring it so I can get different behavior depending on ...
5
votes
2answers
103 views

How to report time and other information on all bash commands? [duplicate]

Most of the things I run in the terminal take a long time to compute and I would like to have bash output a time report at the end of every command entered into the terminal. Is there something I can ...
1
vote
2answers
214 views

.bashrc execute command after “/bin/bash --login”

I have this alias in my .bashrc: alias s='cd ~/Documents/projects/s && /bin/bash --login && rvm use ruby-1.9' How can I execute the right part after it enters login shell (/bin/bash ...
3
votes
1answer
99 views

Change the location of .bashrc

Is it possible to change the location of .bashrc from /home/orhanc/.bashrc to some other directory?
1
vote
1answer
341 views

Aliases in scripts are not set globally

I know this sound really wierd but this is exactly what happens. I have my .profile and .bashrc file set up in a way that the .bash_aliases file gets executed (checked it with a echo). I do not get ...
4
votes
2answers
253 views

How do I execute a command on login for a system user with no home folder and no personal .bashrc file?

I set these users' home folders through the /etc/passwd file, but when they log in I would like them to activate a python virtualenv. If they had a personal .bashrc file, I'd just include the activate ...
3
votes
2answers
509 views

Bash doesn't read .bashrc unless manually started

bash won't source .bashrc from an interactive terminal unless I manually run bash from a terminal: $ bash or manually source it: $ source ./.bashrc or running: $ st -e bash Here's some useful ...
14
votes
2answers
342 views

bash_history: comment out dangerous commands: `#`

To prevent logging "dangerous" commands in bash history, I have added following line to my .bashrc file: HISTIGNORE='rm *:mv *:cp *:cat*>*:pv*>*' this works well, but it has a side effect: I ...
3
votes
4answers
462 views

Bash aliases/functions and command line options

I want to set an alias to start nedit together with command line option -noautosave (due to text files up to 500MB). What seemed to be easy: alias nn="nedit -noautosave $1 &" just raises some ...
1
vote
2answers
355 views

Adding to PS1 in bash_profile

In my .bash_profile currently, I have PS1='\[\e[1;91m\][\u@\h \w]\$\[\e[0m\] '. I am trying to follow these commands to show branch name on iTerm terminal. I changed my PS1='\[\e[1;91m\][\u@\h ...
2
votes
3answers
167 views

sudo command after long sleep call without re-prompting sudo password

I'm trying to write a simple bash function that sleeps X-number of mins and then runs a system sleep command (for me it's sudo pm-suspend since I'm on Ubuntu) right now the function looks like this: ...
7
votes
3answers
775 views

How to tell if terminal session is running within screen

When running a bash script, I would like to be able to tell if it is running within a screen. Is this possible? I want this so that .bashrc can set the colour of the command prompt depending on ...
3
votes
2answers
126 views

How to make .bashrc call dependant on tmux program being installed?

I have a section in my .bashrc that fires up the tmux program (terminal multiplexor). However if the tmux program isn't installed (say I'm setting up a new computer) then having this in my .bashrc ...
0
votes
2answers
484 views

Redirect all stderr of a console and subsequent commands to a file [duplicate]

I know how to redirect stderr to a file or to the stdout when I issue a command: command 2 > log or command 2 > &1 or even command 2 > &1 > /dev/null. However, I want to redirect ...
0
votes
3answers
90 views

I need to turn a series of commands piped together into an alias in .bashrc

sudo ifconfig wlan0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}' The above command when run from terminal outputs the right "internal" ip address. When I try to pass as alias like: alias ...
2
votes
2answers
102 views

Color PS1 based on previous command output [duplicate]

I have my current PS1 as follows. The $? output is really useful (second line). export PS1="\ ${PSOn_Blue}${PSBWhite}\t\ ${PSColor_Off} \$?\ ${PSColor_Off}${PSBGreen} \u\ ${PSColor_Off}${PSWhite}@\ ...
1
vote
0answers
31 views

why bash history overlap the prompt when scroll up in the history? [duplicate]

I customized my bash prompt, PS1 value. ~/.bashrc: Color_Off='\e[0m' # Text Reset BGreen='\e[1;32m' # Green BPurple='\e[1;35m' # Purple BWhite='\e[1;37m' # White ...
2
votes
0answers
312 views

.bashrc alias not working [closed]

I have set up a few aliases in my .bashrc file, like the following: alias ras='rails server' alias res='redis-server' alias rc='rails console' alias be='bundle exec' # git alias's are as follows ...
1
vote
3answers
140 views

In bash, how can I erase an alias without logout? [duplicate]

I had an alias in my .bashrc and I really don't want it anymore. I erased the alias, but my bash already has this alias loaded. Can I erase this alias from this bash without logging out?
3
votes
1answer
92 views

Keep two bash history files, one with ignoredups, one with everything

For the purposes of looking at which commands I am using the most, I'd like to keep a record of command I type in my bash history (even duplicates). But, for sanity and ease of use, I still want to ...
8
votes
1answer
1k views

How can I change screen's hardstatus color based on the logged in user?

I haven't edited/created a .screenrc file in a while, but this is what I'm currently using: # Turn off the screen startup message startup_message off # Define format of bottom ...
4
votes
4answers
1k views

execute bash script inside .bashrc

Hi I am curious if it is possible to execute a bash script inside bash rc. It would seem to create a infinite loop unless there was some way to tell it to not try and start a new shell. Here is an ...
0
votes
1answer
527 views

Login script for bash not loading

I am very confused about the login script for bash. I have always used ~/.bash_profile to configure my bash shell. Now I am on a new system just as a user: I am not root. This system was originally ...
2
votes
1answer
222 views

How to make a permanent variable

In terminal: VAR="Extremely long and often used command" echo $VAR Output: Extremely long and often used command So far it works fine, but after restarting a terminal my variable doesn't ...