Tag Info

Hot answers tagged

249

Traditionally, when you log into a Unix system, the system would start one program for you. That program is a shell, i.e., a program designed to start other programs. It's a command line shell: you start another program by typing its name. The default shell, a Bourne shell, reads commands from ~/.profile when it is invoked as the login shell. Bash is a ...


45

Regarding the problem with .bashrc above: On most systems, ~/.bashrc is only used when starting an interactive non-login shell. However, when you start up a new shell it is often an interactive login shell. Since this is a login shell, the .bashrc is ignored. To keep the environment consistent between non-login and login shells, you must source the .bashrc ...


36

So turns out that on Mac OS X Snow Leopard as well as Mac OS X Lion, the file that's loaded is called .profile, not .bashrc. What you want to do is create a file in ~/.profile and call it .profile (if it doesn't already exists). Put whatever information you needed to load with each instance of bash there (Thanks, thepurplepixel). A couple of side notes: ...


35

From this short article According to the bash man page, .bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells. What is a login or non-login shell? When you login (eg: type username and password) via console, either physically sitting at the machine when booting, or remotely via ssh: ...


22

When you open up your Git Bash, you should be by default in your home directory. Now create the .bashrc file (if on Win7 the file should be named .bashrc.). If you're not in the home directory change into it with: cd You can create the file with: touch .bashrc Then edit it with vim or you could try doing it with some windows editor, but i don't ...


20

Back in the old days, when pseudo tty's weren't pseudo and actually, well, typed, and UNIXes were accessed by modems so slow you could see each letter being printed to your screen, efficiency was paramount. To help efficiency somewhat you had a concept of a main login window and whatever other windows you used to actually work. In your main window, you'd ...


18

bash is probably getting started as a login shell, in which case it doesn't read .bashrc automatically. Instead, it reads .bash_profile. From the Bash manual: So, typically, your `~/.bash_profile' contains the line `if [ -f ~/.bashrc ]; then . ~/.bashrc; fi' after (or before) any login-specific initializations. So in summary, create a ...


15

The following should work: function cd() { builtin cd "$@" && ls -l; } Since the function is on a single line, ensure that it is terminated with ; as above in order to work correctly.


12

You could simply add the following command into System > Preferences > Startup Applications: bash /full/path/to/your/script.sh That should do the trick ;)


12

~/.bash_profile DROPBOX_PROFILE='~/Dropbox/Bash/.bash_profile' if [ -f $DROPBOX_PROFILE ]; then . $DROPBOX_PROFILE fi ~/.emacs (load "~/Dropbox/Emacs/.emacs")


12

Seeing "Broken pipe" in this situation is rare, but normal. When you run type rvm | head -1, bash executes type rvm in one process, head -1 in another.1 The stdout of type is connected to the "write" end of a pipe, the stdin of head to the "read" end. Both processes run at the same time. The head -1 process reads data from stdin (usually in chunks of 8 ...


10

Assuming you’ve verified that it’s a login shell (shopt login_shell): ~/.bash_logout is only run if it you explicitly exit the shell with exit or logout, or by typing Control-D to enter an end-of-file at the command prompt. If you close the terminal emulator, processes are sent SIGHUP, and bash doesn’t run ~/.bash_logout in that case. If you want to ...


8

On a modern system it is not especially common to run into the cases where it matters, but it does happen. (In particular, if you use shell operations in vim such as :r !command or the in-line !<motion>command form.) What would you put under ~/.bashrc? only aliases? You put things in ~/.bashrc that would not be inherited by subshells ...


7

You have to make your own .bashrc. You can simply use a text editor to make a file called .bashrc (no extension) with the contents you want and save it in your home directory (/Users/YourUserName/).


7

I think you're running into a loop. Your cd function is calling cd, which is... the function You need to know about builtin which is a keyword which makes command lookup use the the Bash builtins like cd and not your function function cd { builtin cd "$1" : do something else } Also, calling /usr/bin/cd will never work, even if such a command ...


7

Perhaps you accidentally ran this from csh? $ csh lucid32:~> source if_rc if: Expression Syntax. lucid32:~> cat if_rc if [ -f /etc/bashrc ]; then : fi


6

So basically, as nodiscc suggested, create a desktop launcher: ~/.config/autostart/script.desktop with the following contents: [Desktop Entry] Type=Application Name=Autostart Script Exec=autostart Icon=system-run X-GNOME-Autostart-enabled=true Then create the autostart script: ~/bin/autostart with your bash contents: #!/bin/bash # Execute bash script ...


6

Use a function instead: function quit { osascript <<EOF tell application "$*" to quit EOF }


5

How about this, which avoids having special config files that source the Dropbox versions? $ ln -s ~/Dropbox/Bash/.bash_profile ~/.bash_profile $ ln -s ~/Dropbox/Emacs/.emacs ~/.emacs


5

I suggest not to override the cd because there are some other scripts hijacking the 'cd' function, for example, rvm. It would be better to choose another name, like 'd', instead and don't specify the 'builtin' type in your function; otherwise, the hijacker would not function. I am using the code below: function d() { cd "$@" && ls;}


5

Temporarily fix the PATH, directly in the broken shell: export PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin (This is my PATH, it should mostly work for you as well) Give yourself write permissions for that file, with or without fixing PATH as above: /usr/bin/sudo /bin/chmod u+rwx ...


5

In bash, alias sudo='sudo ' will cause bash to expand any aliases that come after sudo.


5

Summarizing from the other suggestions: Put this in your .bashrc (or preferably, .bash_aliases): alias ls="ls -F --color=auto" Also, a good read would be man dircolors.


5

Add the following line at the end of ~/.bash_profile or ~/.bashrc, whichever exists: PS1="\n$PS1" This will add a newline before a prompt is printed, which is after control is returned to the shell. Unless your command prompt contains shell commands or variables (which would get executed/interpreted at the time of variable assignment), this will work. ...


5

You should edit your ~/.bashrc, and add something like: export PATH=$PATH:/path/to/bin


5

⇧⌘. shows hidden files in file dialogs. You could try opening ~/.bash_profile with TextEdit and making it blank temporarily.


5

You can fix a broken pipe at the expense of another process by inserting tail +1 in your pipe, like this: type rvm | tail +1 | head -1 The +1 option tells tail to print the first line of input and everything that follows. Output will be exactly the same as if tail +1 wasn't there, but the program is smart enough to check standard output and closes the ...


5

You can put .bash_profile in your user directory: C:\Users\<username>. You can also create some git-only aliases so you can do just git st for git status by adding these lines to C:\Users\<username>\.gitconfig: [alias] st = status Some other useful aliases: cm = commit -m cma = commit -a -m br = branch co = checkout df = diff ls = ls-files ...


5

As discussed in Why ~/.bash_profile is not getting sourced when opening a terminal? on “Ask Ubuntu”, the shell running under tmux is not a login shell. How can I tell whether a shell is a “login shell”? Try typing “logout”.  If the shell terminates, it was a login shell.  If it says it isn’t a login shell, then it isn’t. Type “ps -fp$$”.  ...



Only top voted, non community-wiki answers of a minimum length are eligible