Hot answers tagged

346

The simple stuff PATH=$PATH:~/opt/bin PATH=~/opt/bin:$PATH depending on whether you want to add ~/opt/bin at the end (to be searched after all other directories, in case there is a program by the same name in multiple directories) or at the beginning (to be searched before all other directories). You can add multiple entries at the same time. ...


137

As is often the case with obscure terms, the Jargon File has an answer: [Unix: from runcom files on the CTSS system 1962-63, via the startup script /etc/rc] Script file containing startup instructions for an application program (or an entire operating system), usually a text file containing commands of the sort that might have been invoked manually once ...


44

Either way works, but they don't do the same thing: the elements of PATHare checked left to right. In your first example, executables in ~/opt/bin will have precedence over those installed, for example, in /usr/bin, which may or may not be what you want. In particular, from a safety point of view, it is dangerous to add paths to the front, because if ...


31

Another expansion - run control On Tue, 4 Nov 2003, goldwyn rodrigues wrote: Does anyone know what RC (in bashrc/mailrc/... ) means or how it originated? I mean, is it an acronym? If yes, what does it stand for? 'rc' stands for 'run control' and is a a convention adopted from older Unix systems. For more info see this: ...


30

Grepping around in /etc turned up a link that Googling did not. It turns out you can control this in the file /etc/fstab. Just add a line that says none / cygdrive binary 0 0 and the problem should be fixed. No more kludgey fixes in .bashrc, and no messed-up $PATH.


29

The organization of configuration files is much less uniform than your questions seem to imply. There is no "class", there is no "hierarchy", and there is no global "configuration czar" nor committee that decrees a common syntax or other nice clean generalizations like the ones you are seeking. There is only a multitude of separate applications like R, ...


28

A shell is the generic name for any program that gives you a text-interface to interact with the computer. You type a command and the output is shown on screen. Many shells have scripting abilities: Put multiple commands in a script and the shell executes them as if they were typed from the keyboard. Most shells offer additional programming constructs ...


24

alias clear='source ~/.bashrc; \clear' The \ tells bash that you want to invoke the external command, not the alias.


22

This is a question that I was going to post here a few weeks ago. Like terdon, I understood that a .bashrc is only sourced for interactive Bash shells so there should be no need for .bashrc to check if it is running in an interactive shell. Confusingly, all the distributions I use (Ubuntu, RHEL and Cygwin) had some type of check (testing $- or $PS1) to ...


21

Sourcing the changed file will provide access to the newly written alias or function in the current terminal, for example: source ~/.bashrc An alternative syntax: . ~/.bashrc Note that if you have many instances of bash running in your terminal (you mentionned multiple tabs), you will have to run this in every instance.


20

I have a handy bash function called calc: calc () { bc -l <<< "$@" } Example usage: $ calc 65320/670 97.49253731343283582089 $ calc 65320*670 43764400 You can change this to suit yourself. For example: divide() { bc -l <<< "$1/$2" } Note: <<< is a here string which is fed into the stdin of bc. You don't need to ...


19

@StarNamer's answer is generally accurate, though I typically include the following tests to make sure that tmux (1) exists on the system and (2) doesn't try to run within itself: if command -v tmux>/dev/null; then [[ ! $TERM =~ screen ]] && [ -z $TMUX ] && exec tmux fi


18

I would look in /etc/profile.d/ for the offending alias. You could also do the following to find it: grep -r '^alias COMMAND' /etc This will recursively grep through files looking for a line beginning with alias COMMAND. If all else fails, put this at the end of your ~/.bashrc unalias COMMAND


18

In bash, . and source are synonyms. Looking into bash source code, file builtin/source.def, you can see . and source use the same internal function source_builtin: $BUILTIN source $FUNCTION source_builtin $SHORT_DOC source filename [arguments] Execute commands from a file in the current shell. Read and execute commands from FILENAME in the current shell. ...


16

Aliases ls is a command, l and la are most likely aliases which make use of the command ls. If you run the command alias you can find all the aliases on your system. $ alias | grep -E ' l=| la=' This will return all the aliases that match the pattern l=... or la=.... Debugging it further You can also use the command type to see how a particular command ...


16

.bashrc is a shell script that Bash runs whenever it is started interactively. You can put any command in that file that you could type at the command prompt. You put commands here to set up the shell for use in your particular environment, or to customize things to your preferences. A common thing to put in .bashrc are aliases that you want to always be ...


15

alias without parameter outputs the definitions of currently defined aliases. declare -f outputs the definitions of currently defined functions. export -p outputs the definitions of currently defined variables. All those commands output definitions ready to be reused, you can redirect their outputs directly to a new ~/.bashrc. All lists will contain a ...


15

I'm confused by question 2 (since removed from the question since it was due to an unrelated issue): What's a workable way to append more paths on different lines? Initially I thought this could do the trick: export PATH=$PATH:~/opt/bin export PATH=$PATH:~/opt/node/bin but it doesn't because the second assignment doesn't only append ...


15

Use unset as last line in your .bashrc: unset -f do_stuff will delete/unset the function do_stuff. To delete/unset the variables invoke it as follows: unset variablename


15

You only need export for variables that should be "seen" by other programs which you launch in the shell, while the ones that are only used inside the shell itself don't need to be exported. This is what the man page says: The supplied names are marked for automatic export to the environā€ ment of subsequently executed commands. If the -f option is ...


15

Easy trick for alias in $(compgen -a); do type $alias; done


14

There's a few things you can try: use bash -v to see what lines are being read during shell startup use bash -x to see what commands are being run during shell startup run with only one startup file bash -v The -v option makes bash print each line from every script file it reads as it reads it. Start by running bash -i -v >bash-i.out 2>&1 ...


13

This seems to work... https://wiki.archlinux.org/index.php/Tmux#Start_tmux_on_every_shell_login Simply add the following line of bash code to your .bashrc before your aliases; the code for other shells is very similar: [[ $TERM != "screen" ]] && exec tmux


13

You can use type to find out how a command would be interpreted by bash.


12

. is the Bourne and POSIX shell command while source is the C-Shell command. Some Bourne-shell derivatives like bash, zsh and most implementations of ksh also have a source command which is generally an alias for . though for ksh with differences. For bash and zsh, . and source behave the same, but their behavior is affected by whether they run in POSIX ...


12

.bashrc and .bash_profile are NOT scripts. They're configuration file which get sourced every time bash is executed in one of 2 ways: interactive login The INVOCATION section of the bash man page is what's relevent. A login shell is one whose first character of argument zero is a -, or one started with the --login option. An interactive shell ...


12

Why would it source it? You are not running true bash: $ echo $SHELL /bin/sh In most modern systems sh is a symlink to a basic shell. On my Debian for example: $ ls -l /bin/sh lrwxrwxrwx 1 root root 4 Aug 1 2012 /bin/sh -> dash In your case, sh is a link to bash but, as explained in man bash: If bash is invoked with the name sh, it tries ...


12

The man page neglects to mention that bash also sources .bashrc for non-interactive remote shells, as in ssh hostname command http://git.savannah.gnu.org/cgit/bash.git/tree/shell.c#n1010 COMMAND EXECUTE BASHRC -------------------------------- bash -c foo NO bash foo NO foo NO rsh machine ls YES (for rsh, ...


11

Linux determines the executable search path with the $PATH environment variable. To add directory /data/myscripts to the beginning of the $PATH environment variable, use the following: PATH=/data/myscripts:$PATH To add that directory to the end of the path, use the following command: PATH=$PATH:/data/myscripts But the preceding are not sufficient ...


11

Why wouldn't they be? They're only executed by their respective shells though... csh and bash are different programs that happen to do similar functions.



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