Tag Info

Hot answers tagged

135

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. ...


24

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, ...


24

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 ...


24

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


20

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.


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. ...


15

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


14

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 ...


14

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 ...


13

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 ...


12

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


12

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


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.


11

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 that ...


11

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


11

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 ...


10

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 ...


10

I'm not going to exactly answer your question, but maybe give you an alternate solution to your problem. If I understand correctly you're concerned about mistakes you could make by typing, e.g., !rm if it happened that the previous rm command in history removes something you'd like to keep. In this case, a nice bash option is histverify. If you shopt -s ...


10

You can almost definitely just do: alias >>./bash_aliases


9

To detect an SSH session, use $SSH_CLIENT. To distinguish between local and remote sessions, there are two possible approaches: client-side or server-side. On the server side, compare $SSH_CLIENT with the local IP address or routing table; this'll usually tell you whether the connection is from the LAN. On the client side, you may want to put ForwardX11 ...


9

. 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 ...


9

This is POSIX's definition of .dot: The shell shall execute commands from the file in the current environment. If file does not contain a /<slash>, the shell shall use the search path specified by $PATH to find the directory containing file. Unlike normal command search, however, the file searched for by the .dot utility need not be ...


8

You can put it in your .bash_profile, which gets executed everytime you log in. Or if it is an alias for a long command, you can put this in your .bash_aliases file under your home directory: alias short_version="very long command here"


8

.bashrc scripts are only run by bash itself. They're not free-standing, and they're not intended to be executed by the system. (In fact, they're generally not marked executable, and, as you say, they don't have a shebang line.) Such scripts are intended to be sourced, since they generally do things like change environment variables ($PATH, for example), ...


8

.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 ...


8

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 ...


8

Yes. You have three main options: Symlink ~/.bashrc, mv ~/.bashrc ~/blah && ln -s ~/blah/.bashrc ~/.bashrc source the new file from ~/.bashrc, mv ~/.bashrc ~/blah && cat > ~/.bashrc << 'EOF' . ~/blah/.bashrc EOF or launch bash with --rcfile. mv ~/.bashrc ~/blah bash --rcfile ~/blah/.bashrc


7

Not only is it possible, some systems set up new accounts with both. This allows the same skeleton setup to be used whichever shell the user gets. The purpose of the two file is the same, but they belong to two different shell families. The syntax of the shell scripts for the two shells is very different so different scripts are required. With a bit of ...


7

You could ignore the builtin history mechanism and abuse $PROMPT_COMMAND to write history any way you wanted. Some people keep a directory of history files, one for each shell/date/hostname, etc. Approx something like this: prompt_cmd() { echo "$_" >> $HOME/.my_history_file_$HOSTNAME } PROMPT_COMMAND=prompt_cmd obviously embellish with dates, ...


7

You could do something like: fixhist() { local cmd histnum cmd=$(HISTTIMEFORMAT=/ history 1) histnum=$((${cmd%%[*/]*})) cmd=${cmd#*/} # remove the histnum case $cmd in (rm\ *|mv\ *|...) history -d "$histnum" # delete history -s "#$cmd" # add back with a # esac } PROMPT_COMMAND=fixhist The idea being that before each ...



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